Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH 00/10] Move help messages of CLI in shell.py
@ 2019-06-24  7:11 yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 01/10] controller: move vf help msg to SppVf.help yasufum.o
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

SPP CLI uses python standard `cmd` library for implementing interactive
environment. For using `help` command of `cmd` lib, you define help
message as a comment of method starts with `do_` which defines a
behaviour of command as default.

However, SPP CLI have got supported many commands and the number of
lines of `shell.py` is over 1,000 or more. It should be changed to
move help messages outside of the file for considering to add
additional commands in future releases possibly.

This series of update is to fix the issue. Add methods start with
`help_` and define help messages in the methods because `cmd` calls
it for help instead of using comments if defined. By this update,
all of classes defined in `src/controller/commands` has method help()
for the message. For some of commands which are implemented without
class, such as `pwd` or `ls`, it is changed to define help messages as
a dict of command name and message in `help_msg.py`.

Yasufumi Ogawa (10):
  controller: move vf help msg to SppVf.help
  controller: move server help msg to SppCtlServer
  controller: move pri help msg to SppPrimary
  controller: move nfv help msg to SppNfv
  controller: move mirror help msg to SppMirror
  controller: move pcap help msg to SppPcap
  controller: move bye help msg to SppBye
  controller: move topo help msg to SppBye
  controller: move status cmd help msg to help_msg
  controller: move rest of help msg to help_msg

 src/controller/commands/bye.py      |  19 ++
 src/controller/commands/help_msg.py | 131 ++++++++
 src/controller/commands/mirror.py   |  36 +++
 src/controller/commands/nfv.py      |  19 ++
 src/controller/commands/pcap.py     |  24 ++
 src/controller/commands/pri.py      |  17 ++
 src/controller/commands/server.py   |  33 +++
 src/controller/commands/topo.py     |  52 ++++
 src/controller/commands/vf.py       |  54 ++++
 src/controller/shell.py             | 443 ++++++++--------------------
 10 files changed, 513 insertions(+), 315 deletions(-)
 create mode 100644 src/controller/commands/help_msg.py

-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [spp] [PATCH 01/10] controller: move vf help msg to SppVf.help
  2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
@ 2019-06-24  7:11 ` yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 02/10] controller: move server help msg to SppCtlServer yasufum.o
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

SPP CLI is implemented with python's cmd library and help message is
defined as a comment of `do_*` method. However, total number of lines
tends to be a large number if the number of command is increased.

To avoid such a situation, this update is to move comment of `do_vf`
to `SppVf.help` to reduce the number of lines.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/vf.py | 54 +++++++++++++++++++++++++++++++++++
 src/controller/shell.py       | 46 ++++-------------------------
 2 files changed, 59 insertions(+), 41 deletions(-)

diff --git a/src/controller/commands/vf.py b/src/controller/commands/vf.py
index b673f0f..c6192e0 100644
--- a/src/controller/commands/vf.py
+++ b/src/controller/commands/vf.py
@@ -501,3 +501,57 @@ class SppVf(object):
                             if 'RES_UID'.startswith(sub_tokens[5]):
                                 res.append('RES_UID')
             return res
+
+    @classmethod
+    def help(cls):
+        msg = """Send a command to spp_vf.
+
+        SPP VF is a secondary process for pseudo SR-IOV features. This
+        command has four sub commands.
+          * status
+          * component
+          * port
+          * classifier_table
+
+        Each of sub commands other than 'status' takes several parameters
+        for detailed operations. Notice that 'start' for launching a worker
+        is replaced with 'stop' for terminating. 'add' is also replaced with
+        'del' for deleting.
+
+        Examples:
+
+        # (1) show status of worker threads and resources
+        spp > vf 1; status
+
+        # (2) launch or terminate a worker thread with arbitrary name
+        #   NAME: arbitrary name used as identifier
+        #   CORE_ID: one of unused cores referred from status
+        #   ROLE: role of workers, 'forward', 'merge' or 'classifier_mac'
+        spp > vf 1; component start NAME CORE_ID ROLE
+        spp > vf 1; component stop NAME CORE_ID ROLE
+
+        # (3) add or delete a port to worker of NAME
+        #   RES_UID: resource UID such as 'ring:0' or 'vhost:1'
+        #   DIR: 'rx' or 'tx'
+        spp > vf 1; port add RES_UID DIR NAME
+        spp > vf 1; port del RES_UID DIR NAME
+
+        # (4) add or delete a port with vlan ID to worker of NAME
+        #   VID: vlan ID
+        #   PCP: priority code point defined in IEEE 802.1p
+        spp > vf 1; port add RES_UID DIR NAME add_vlantag VID PCP
+        spp > vf 1; port del RES_UID DIR NAME add_vlantag VID PCP
+
+        # (5) add a port of deleting vlan tag
+        spp > vf 1; port add RES_UID DIR NAME del_vlantag
+
+        # (6) add or delete an entry of MAC address and resource to classify
+        spp > vf 1; classifier_table add mac MAC_ADDR RES_UID
+        spp > vf 1; classifier_table del mac MAC_ADDR RES_UID
+
+        # (7) add or delete an entry of MAC address and resource with vlan ID
+        spp > vf 1; classifier_table add vlan VID MAC_ADDR RES_UID
+        spp > vf 1; classifier_table del vlan VID MAC_ADDR RES_UID
+        """
+
+        print(msg)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 057f70a..75dabaa 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -406,52 +406,12 @@ class Shell(cmd.Cmd, object):
     def do_vf(self, cmd):
         """Send a command to spp_vf.
 
-        SPP VF is a secondary process for pseudo SR-IOV features. This
+        spp_vf is a secondary process for pseudo SR-IOV features. This
         command has four sub commands.
           * status
           * component
           * port
           * classifier_table
-
-        Each of sub commands other than 'status' takes several parameters
-        for detailed operations. Notice that 'start' for launching a worker
-        is replaced with 'stop' for terminating. 'add' is also replaced with
-        'del' for deleting.
-
-        Examples:
-
-        # (1) show status of worker threads and resources
-        spp > vf 1; status
-
-        # (2) launch or terminate a worker thread with arbitrary name
-        #   NAME: arbitrary name used as identifier
-        #   CORE_ID: one of unused cores referred from status
-        #   ROLE: role of workers, 'forward', 'merge' or 'classifier_mac'
-        spp > vf 1; component start NAME CORE_ID ROLE
-        spp > vf 1; component stop NAME CORE_ID ROLE
-
-        # (3) add or delete a port to worker of NAME
-        #   RES_UID: resource UID such as 'ring:0' or 'vhost:1'
-        #   DIR: 'rx' or 'tx'
-        spp > vf 1; port add RES_UID DIR NAME
-        spp > vf 1; port del RES_UID DIR NAME
-
-        # (4) add or delete a port with vlan ID to worker of NAME
-        #   VID: vlan ID
-        #   PCP: priority code point defined in IEEE 802.1p
-        spp > vf 1; port add RES_UID DIR NAME add_vlantag VID PCP
-        spp > vf 1; port del RES_UID DIR NAME add_vlantag VID PCP
-
-        # (5) add a port of deleting vlan tag
-        spp > vf 1; port add RES_UID DIR NAME del_vlantag
-
-        # (6) add or delete an entry of MAC address and resource to classify
-        spp > vf 1; classifier_table add mac MAC_ADDR RES_UID
-        spp > vf 1; classifier_table del mac MAC_ADDR RES_UID
-
-        # (7) add or delete an entry of MAC address and resource with vlan ID
-        spp > vf 1; classifier_table add vlan VID MAC_ADDR RES_UID
-        spp > vf 1; classifier_table del vlan VID MAC_ADDR RES_UID
         """
 
         # remove unwanted spaces to avoid invalid command error
@@ -466,6 +426,10 @@ class Shell(cmd.Cmd, object):
         else:
             print('Invalid command: %s' % tmparg)
 
+    def help_vf(self):
+        """Print help message of spp_vf."""
+        vf.SppVf.help()
+
     def complete_vf(self, text, line, begidx, endidx):
         """Completion for vf command."""
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [spp] [PATCH 02/10] controller: move server help msg to SppCtlServer
  2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 01/10] controller: move vf help msg to SppVf.help yasufum.o
@ 2019-06-24  7:11 ` yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 03/10] controller: move pri help msg to SppPrimary yasufum.o
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This patch is to move comment of `do_server` to `SppCtlServer.help` to
reduce the number of lines.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/server.py | 33 +++++++++++++++++++++++++++++++
 src/controller/shell.py           | 33 +++++--------------------------
 2 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/src/controller/commands/server.py b/src/controller/commands/server.py
index c2bda9d..2b5913a 100644
--- a/src/controller/commands/server.py
+++ b/src/controller/commands/server.py
@@ -258,3 +258,36 @@ class SppCtlServer(object):
                 removed.ip_addr, removed.port))
 
         return True
+
+    @classmethod
+    def help(cls):
+        msg = """Switch SPP REST API server.
+
+        Show a list of servers. '*' means that it is under the control.
+
+            spp > server  # or 'server list'
+              1: 192.168.1.101:7777 *
+              2: 192.168.1.102:7777
+
+        Switch to the second node with index or address.
+
+            spp > server 2
+            Switch spp-ctl to "2: 192.168.1.102:7777".
+
+            # It is the same
+            spp > server 192.168.1.101  # no need port if default
+            Switch spp-ctl to "1: 192.168.1.101:7777".
+
+        Register or unregister a node by using 'add' or 'del' command.
+        For unregistering, node is also specified with index.
+
+            # Register third node
+            spp > server add 192.168.122.177
+            Registered spp-ctl "192.168.122.177:7777".
+
+            # Unregister second one
+            spp > server del 2  # or 192.168.1.102
+            Unregistered spp-ctl "192.168.1.102:7777".
+        """
+
+        print(msg)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 75dabaa..b86ba5c 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -253,38 +253,15 @@ class Shell(cmd.Cmd, object):
             self.recorded_file = None
 
     def do_server(self, commands):
-        """Switch SPP REST API server.
-
-        Show a list of servers. '*' means that it is under the control.
-
-            spp > server  # or 'server list'
-              1: 192.168.1.101:7777 *
-              2: 192.168.1.102:7777
-
-        Switch to the second node with index or address.
-
-            spp > server 2
-            Switch spp-ctl to "2: 192.168.1.102:7777".
-
-            # It is the same
-            spp > server 192.168.1.101  # no need port if default
-            Switch spp-ctl to "1: 192.168.1.101:7777".
-
-        Register or unregister a node by using 'add' or 'del' command.
-        For unregistering, node is also specified with index.
-
-            # Register third node
-            spp > server add 192.168.122.177
-            Registered spp-ctl "192.168.122.177:7777".
-
-            # Unregister second one
-            spp > server del 2  # or 192.168.1.102
-            Unregistered spp-ctl "192.168.1.102:7777".
-        """
+        """Switch SPP REST API server."""
 
         self.spp_ctl_server.run(commands)
         self.spp_ctl_cli = self.spp_ctl_server.get_current_server()
 
+    def help_server(self):
+        """Print help message of server command."""
+        server.SppCtlServer.help()
+
     def complete_server(self, text, line, begidx, endidx):
         """Completion for server command."""
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [spp] [PATCH 03/10] controller: move pri help msg to SppPrimary
  2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 01/10] controller: move vf help msg to SppVf.help yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 02/10] controller: move server help msg to SppCtlServer yasufum.o
@ 2019-06-24  7:11 ` yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 04/10] controller: move nfv help msg to SppNfv yasufum.o
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This patch is to move comment of `do_pri` to `SppPrimary.help` to
reduce the number of lines.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/pri.py | 17 +++++++++++++++++
 src/controller/shell.py        | 33 +++++++--------------------------
 2 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/src/controller/commands/pri.py b/src/controller/commands/pri.py
index 15bdb12..b119a5c 100644
--- a/src/controller/commands/pri.py
+++ b/src/controller/commands/pri.py
@@ -436,3 +436,20 @@ class SppPrimary(object):
                 pass
             else:
                 print('Error: unknown response.')
+
+    @classmethod
+    def help(cls):
+        msg = """Send a command to primary process.
+
+        Show resources and statistics, or clear it.
+            spp > pri; status  # show status
+            spp > pri; clear   # clear statistics
+
+        Launch secondary process..
+            # Launch nfv:1
+            spp > pri; launch nfv 1 -l 1,2 -m 512 -- -n 1 -s 192.168....
+            # Launch vf:2
+            spp > pri; launch vf 2 -l 1,4-7 -m 512 -- --client-id 2 -s ...
+        """
+
+        print(msg)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index b86ba5c..bfe963b 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -278,22 +278,7 @@ class Shell(cmd.Cmd, object):
         self.print_status()
 
     def do_pri(self, command):
-        """Send a command to primary process.
-
-        Show resources and statistics, or clear it.
-
-            spp > pri; status  # show status
-
-            spp > pri; clear   # clear statistics
-
-        Launch secondary process..
-
-            # Launch nfv:1
-            spp > pri; launch nfv 1 -l 1,2 -m 512 -- -n 1 -s 192.168....
-
-            # Launch vf:2
-            spp > pri; launch vf 2 -l 1,4-7 -m 512 -- --client-id 2 -s ...
-        """
+        """Send a command to primary process."""
 
         # Remove unwanted spaces and first char ';'
         command = self.clean_cmd(command)[1:]
@@ -303,6 +288,10 @@ class Shell(cmd.Cmd, object):
 
         self.primary.run(command, self.cli_config)
 
+    def help_pri(self):
+        """Print help message of pri command."""
+        pri.SppPrimary.help()
+
     def complete_pri(self, text, line, begidx, endidx):
         """Completion for primary process commands."""
 
@@ -381,15 +370,7 @@ class Shell(cmd.Cmd, object):
                 return res
 
     def do_vf(self, cmd):
-        """Send a command to spp_vf.
-
-        spp_vf is a secondary process for pseudo SR-IOV features. This
-        command has four sub commands.
-          * status
-          * component
-          * port
-          * classifier_table
-        """
+        """Send a command to spp_vf."""
 
         # remove unwanted spaces to avoid invalid command error
         tmparg = self.clean_cmd(cmd)
@@ -404,7 +385,7 @@ class Shell(cmd.Cmd, object):
             print('Invalid command: %s' % tmparg)
 
     def help_vf(self):
-        """Print help message of spp_vf."""
+        """Print help message of vf command."""
         vf.SppVf.help()
 
     def complete_vf(self, text, line, begidx, endidx):
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [spp] [PATCH 04/10] controller: move nfv help msg to SppNfv
  2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
                   ` (2 preceding siblings ...)
  2019-06-24  7:11 ` [spp] [PATCH 03/10] controller: move pri help msg to SppPrimary yasufum.o
@ 2019-06-24  7:11 ` yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 05/10] controller: move mirror help msg to SppMirror yasufum.o
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This patch is to move comment of `do_nfv` to `SppNfv.help` to reduce
the number of lines.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/nfv.py | 19 +++++++++++++++++++
 src/controller/shell.py        | 19 +++++--------------
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/controller/commands/nfv.py b/src/controller/commands/nfv.py
index 92d2a3f..0989eba 100644
--- a/src/controller/commands/nfv.py
+++ b/src/controller/commands/nfv.py
@@ -442,3 +442,22 @@ class SppNfv(object):
                 pass
             else:
                 print('Error: unknown response.')
+
+    @classmethod
+    def help(cls):
+        msg = """Send a command to spp_nfv specified with ID.
+
+        Spp_nfv is specified with secondary ID and takes sub commands.
+
+          spp > nfv 1; status
+          spp > nfv 1; add ring:0
+          spp > nfv 1; patch phy:0 ring:0
+
+        You can refer all of sub commands by pressing TAB after
+        'nfv 1;'.
+
+          spp > nfv 1;  # press TAB
+          add     del     exit    forward patch   status  stop
+        """
+
+        print(msg)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index bfe963b..b11dac0 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -302,20 +302,7 @@ class Shell(cmd.Cmd, object):
                 self.cli_config)
 
     def do_nfv(self, cmd):
-        """Send a command to spp_nfv specified with ID.
-
-        Spp_nfv is specified with secondary ID and takes sub commands.
-
-        spp > nfv 1; status
-        spp > nfv 1; add ring:0
-        spp > nfv 1; patch phy:0 ring:0
-
-        You can refer all of sub commands by pressing TAB after
-        'nfv 1;'.
-
-        spp > nfv 1;  # press TAB
-        add     del     exit    forward patch   status  stop
-        """
+        """Send a command to spp_nfv specified with ID."""
 
         # remove unwanted spaces to avoid invalid command error
         tmparg = self.clean_cmd(cmd)
@@ -328,6 +315,10 @@ class Shell(cmd.Cmd, object):
         else:
             print('Invalid command: %s' % tmparg)
 
+    def help_nfv(self):
+        """Print help message of nfv command."""
+        nfv.SppNfv.help()
+
     def complete_nfv(self, text, line, begidx, endidx):
         """Completion for nfv command."""
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [spp] [PATCH 05/10] controller: move mirror help msg to SppMirror
  2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
                   ` (3 preceding siblings ...)
  2019-06-24  7:11 ` [spp] [PATCH 04/10] controller: move nfv help msg to SppNfv yasufum.o
@ 2019-06-24  7:11 ` yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 06/10] controller: move pcap help msg to SppPcap yasufum.o
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This patch is to move comment of `do_mirror` to `SppMirror.help` to
reduce the number of lines.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/mirror.py | 36 +++++++++++++++++++++++++++++++
 src/controller/shell.py           | 36 +++++--------------------------
 2 files changed, 41 insertions(+), 31 deletions(-)

diff --git a/src/controller/commands/mirror.py b/src/controller/commands/mirror.py
index d38812d..d7ea4cd 100644
--- a/src/controller/commands/mirror.py
+++ b/src/controller/commands/mirror.py
@@ -356,3 +356,39 @@ class SppMirror(object):
                         if kw.startswith(sub_tokens[4]):
                             res.append(kw)
             return res
+
+    @classmethod
+    def help(cls):
+        msg = """Send a command to spp_mirror.
+
+        spp_mirror is a secondary process for duplicating incoming
+        packets to be used as similar to TaaS in OpenStack. This
+        command has four sub commands.
+          * status
+          * component
+          * port
+
+        Each of sub commands other than 'status' takes several parameters
+        for detailed operations. Notice that 'start' for launching a worker
+        is replaced with 'stop' for terminating. 'add' is also replaced with
+        'del' for deleting.
+
+        Examples:
+
+        # (1) show status of worker threads and resources
+        spp > mirror 1; status
+
+        # (2) launch or terminate a worker thread with arbitrary name
+        #   NAME: arbitrary name used as identifier
+        #   CORE_ID: one of unused cores referred from status
+        spp > mirror 1; component start NAME CORE_ID mirror
+        spp > mirror 1; component stop NAME CORE_ID mirror
+
+        # (3) add or delete a port to worker of NAME
+        #   RES_UID: resource UID such as 'ring:0' or 'vhost:1'
+        #   DIR: 'rx' or 'tx'
+        spp > mirror 1; port add RES_UID DIR NAME
+        spp > mirror 1; port del RES_UID DIR NAME
+        """
+
+        print(msg)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index b11dac0..2682376 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -418,37 +418,7 @@ class Shell(cmd.Cmd, object):
                         self.get_sec_ids('vf'), text, line, begidx, endidx)
 
     def do_mirror(self, cmd):
-        """Send a command to spp_mirror.
-
-        spp_mirror is a secondary process for duplicating incoming
-        packets to be used as similar to TaaS in OpenStack. This
-        command has four sub commands.
-          * status
-          * component
-          * port
-
-        Each of sub commands other than 'status' takes several parameters
-        for detailed operations. Notice that 'start' for launching a worker
-        is replaced with 'stop' for terminating. 'add' is also replaced with
-        'del' for deleting.
-
-        Examples:
-
-        # (1) show status of worker threads and resources
-        spp > mirror 1; status
-
-        # (2) launch or terminate a worker thread with arbitrary name
-        #   NAME: arbitrary name used as identifier
-        #   CORE_ID: one of unused cores referred from status
-        spp > mirror 1; component start NAME CORE_ID mirror
-        spp > mirror 1; component stop NAME CORE_ID mirror
-
-        # (3) add or delete a port to worker of NAME
-        #   RES_UID: resource UID such as 'ring:0' or 'vhost:1'
-        #   DIR: 'rx' or 'tx'
-        spp > mirror 1; port add RES_UID DIR NAME
-        spp > mirror 1; port del RES_UID DIR NAME
-        """
+        """Send a command to spp_mirror."""
 
         # remove unwanted spaces to avoid invalid command error
         tmparg = self.clean_cmd(cmd)
@@ -461,6 +431,10 @@ class Shell(cmd.Cmd, object):
         else:
             print('Invalid command: %s' % tmparg)
 
+    def help_mirror(self):
+        """Print help message of mirror command."""
+        mirror.SppMirror.help()
+
     def complete_mirror(self, text, line, begidx, endidx):
         """Completion for mirror command."""
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [spp] [PATCH 06/10] controller: move pcap help msg to SppPcap
  2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
                   ` (4 preceding siblings ...)
  2019-06-24  7:11 ` [spp] [PATCH 05/10] controller: move mirror help msg to SppMirror yasufum.o
@ 2019-06-24  7:11 ` yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 07/10] controller: move bye help msg to SppBye yasufum.o
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This patch is to move comment of `do_pcap` to `SppPcap.help` to
reduce the number of lines.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/pcap.py | 24 ++++++++++++++++++++++++
 src/controller/shell.py         | 24 +++++-------------------
 2 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/controller/commands/pcap.py b/src/controller/commands/pcap.py
index 88dd5c8..f2e1ffa 100644
--- a/src/controller/commands/pcap.py
+++ b/src/controller/commands/pcap.py
@@ -239,3 +239,27 @@ class SppPcap(object):
                             status['core_ids'].append(wk['core'])
 
         return status
+
+    @classmethod
+    def help(cls):
+        msg = """Send a command to spp_pcap.
+
+        Spp_pcap is a secondary process for capturing incoming packets.
+
+        'start' for launching a worker is replaced with 'stop' for
+        terminating. 'exit' for spp_pcap terminating.
+
+        Examples:
+
+        # (1) show status of worker threads and resources
+        spp > pcap 1; status
+
+        # (2) launch or terminate capture thread
+        spp > pcap 1; start
+        spp > pcap 1; stop
+
+        # (3) terminate spp_pcap secondaryd
+        spp > pcap 1; exit
+        """
+
+        print(msg)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 2682376..52fe645 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -475,25 +475,7 @@ class Shell(cmd.Cmd, object):
                         self.get_sec_ids('mirror'), text, line, begidx, endidx)
 
     def do_pcap(self, cmd):
-        """Send a command to spp_pcap.
-
-        Spp_pcap is a secondary process for capturing incoming packets.
-
-        'start' for launching a worker is replaced with 'stop' for
-        terminating. 'exit' for spp_pcap terminating.
-
-        Examples:
-
-        # (1) show status of worker threads and resources
-        spp > pcap 1; status
-
-        # (2) launch or terminate capture thread
-        spp > pcap 1; start
-        spp > pcap 1; stop
-
-        # (3) terminate spp_pcap secondaryd
-        spp > pcap 1; exit
-        """
+        """Send a command to spp_pcap."""
 
         # remove unwanted spaces to avoid invalid command error
         tmparg = self.clean_cmd(cmd)
@@ -506,6 +488,10 @@ class Shell(cmd.Cmd, object):
         else:
             print('Invalid command: {}'.format(tmparg))
 
+    def help_pcap(self):
+        """Print help message of pcap command."""
+        pcap.SppPcap.help()
+
     def complete_pcap(self, text, line, begidx, endidx):
         """Completion for pcap command."""
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [spp] [PATCH 07/10] controller: move bye help msg to SppBye
  2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
                   ` (5 preceding siblings ...)
  2019-06-24  7:11 ` [spp] [PATCH 06/10] controller: move pcap help msg to SppPcap yasufum.o
@ 2019-06-24  7:11 ` yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 08/10] controller: move topo " yasufum.o
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This patch is to move comment of `do_bye` to `SppBye.help` to reduce
the number of lines.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/bye.py | 19 +++++++++++++++++++
 src/controller/shell.py        | 19 +++++--------------
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/controller/commands/bye.py b/src/controller/commands/bye.py
index cd14961..df06500 100644
--- a/src/controller/commands/bye.py
+++ b/src/controller/commands/bye.py
@@ -47,3 +47,22 @@ class SppBye(object):
         for sec_type, spp_procs in spp_secondaries.items():
             for sec in spp_procs.values():
                 sec.run('exit')
+
+    @classmethod
+    def help(cls):
+        msg = """Terminate SPP processes and controller.
+
+        There are three usages for terminating processes.
+        It terminates logging if you activated recording.
+
+        (1) Terminate secondary processes
+            spp > bye sec
+
+        (2) Terminate primary and secondary processes
+            spp > bye all
+
+        (3) Terminate SPP controller (not for primary and secondary)
+            spp > bye
+        """
+
+        print(msg)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 52fe645..8cb74a0 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -696,20 +696,7 @@ class Shell(cmd.Cmd, object):
         return common.compl_common(text, line)
 
     def do_bye(self, args):
-        """Terminate SPP processes and controller.
-
-        There are three usages for terminating processes.
-        It terminates logging if you activated recording.
-
-        (1) Terminate secondary processes
-        spp > bye sec
-
-        (2) Terminate primary and secondary processes
-        spp > bye all
-
-        (3) Terminate SPP controller (not for primary and secondary)
-        spp > bye
-        """
+        """Terminate SPP processes and controller."""
 
         cmds = args.split(' ')
         if cmds[0] == '':  # terminate SPP CLI itself
@@ -719,6 +706,10 @@ class Shell(cmd.Cmd, object):
             spp_bye = bye.SppBye()
             spp_bye.run(args, self.primary, self.secondaries)
 
+    def help_bye(self):
+        """Print help message of bye command."""
+        bye.SppBye.help()
+
     def complete_bye(self, text, line, begidx, endidx):
         """Completion for bye commands"""
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [spp] [PATCH 08/10] controller: move topo help msg to SppBye
  2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
                   ` (6 preceding siblings ...)
  2019-06-24  7:11 ` [spp] [PATCH 07/10] controller: move bye help msg to SppBye yasufum.o
@ 2019-06-24  7:11 ` yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 09/10] controller: move status cmd help msg to help_msg yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 10/10] controller: move rest of " yasufum.o
  9 siblings, 0 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This patch is to move comment of `do_topo`, `do_topo_subgraph` and
`do_topo_resize` to `SppTopo.help` to reduce the number of lines.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/topo.py | 52 ++++++++++++++++++++++++++++
 src/controller/shell.py         | 61 +++++++++------------------------
 2 files changed, 68 insertions(+), 45 deletions(-)

diff --git a/src/controller/commands/topo.py b/src/controller/commands/topo.py
index 3b24c1a..21ef1ec 100644
--- a/src/controller/commands/topo.py
+++ b/src/controller/commands/topo.py
@@ -459,3 +459,55 @@ class SppTopo(object):
             return True
         else:
             return False
+
+    @classmethod
+    def help(cls):
+        msg = """Output network topology.
+
+        Support four types of output.
+        * terminal (but very few terminals supporting to display images)
+        * browser (websocket server is required)
+        * image file (jpg, png, bmp)
+        * text (dot, js or json, yml or yaml)
+
+        spp > topo term  # terminal
+        spp > topo http  # browser
+        spp > topo network_conf.jpg  # image
+        spp > topo network_conf.dot  # text
+        spp > topo network_conf.js# text
+        """
+
+        print(msg)
+
+    @classmethod
+    def help_resize(cls):
+        msg = """Change the size of the image of topo command.
+
+        You can specify the size by percentage or ratio.
+
+        spp > topo resize 60%  # percentage
+        spp > topo resize 0.6  # ratio
+        """
+
+        print(msg)
+
+    @classmethod
+    def help_subgraph(cls):
+        msg = """Edit subgarph for topo command.
+
+        Subgraph is a group of object defined in dot language. For topo
+        command, it is used for grouping resources of each of VM or
+        container to topology be more understandable.
+
+        (1) Add subgraph labeled 'vm1'.
+            spp > topo_subgraph add vm1 vhost:1;vhost:2
+
+        (2) Delete subgraph 'vm1'.
+            spp > topo_subgraph del vm1
+
+        (3) Show subgraphs by running topo_subgraph without args.
+            spp > topo_subgraph
+            label: vm1	subgraph: "vhost:1;vhost:2"
+        """
+
+        print(msg)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 8cb74a0..54376c9 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -824,11 +824,7 @@ class Shell(cmd.Cmd, object):
         {'cmdqueue': [],
          'completekey': 'tab',
          'completion_matches': ['inspect'],
-         'lastcmd': 'inspect',
-         'old_completer': None,
-         'stdin': <open file '<stdin>', mode 'r' at 0x7fe96bddf0c0>,
-         'stdout': <open file '<stdout>', mode 'w' at 0x7fe96bddf150>}
-
+         ...
         """
 
         from pprint import pprint
@@ -841,22 +837,7 @@ class Shell(cmd.Cmd, object):
         return ['add', 'del']
 
     def do_topo_subgraph(self, args):
-        """Edit subgarph for topo command.
-
-        Subgraph is a group of object defined in dot language. For topo
-        command, it is used for grouping resources of each of VM or
-        container to topology be more understandable.
-
-        (1) Add subgraph labeled 'vm1'.
-        spp > topo_subgraph add vm1 vhost:1;vhost:2
-
-        (2) Delete subgraph 'vm1'.
-        spp > topo_subgraph del vm1
-
-        (3) Show subgraphs by running topo_subgraph without args.
-        spp > topo_subgraph
-        label: vm1	subgraph: "vhost:1;vhost:2"
-        """
+        """Edit subgarph for topo command."""
 
         # logger.info("Topo initialized with sec IDs %s" % sec_ids)
 
@@ -897,6 +878,10 @@ class Shell(cmd.Cmd, object):
             else:
                 print("Ivalid subcommand '%s'!" % tokens[0])
 
+    def help_topo_subgraph(self):
+        """Print help message of topo_subgraph command."""
+        topo.SppTopo.help_subgraph()
+
     def complete_topo_subgraph(self, text, line, begidx, endidx):
         terms = self.terms_topo_subgraph()
 
@@ -921,35 +906,21 @@ class Shell(cmd.Cmd, object):
             pass
 
     def do_topo_resize(self, args):
-        """Change the size of the image of topo command.
-
-        You can specify the size by percentage or ratio.
-
-        spp > topo resize 60%  # percentage
-        spp > topo resize 0.6  # ratio
-
-        """
-
+        """Change the size of the image of topo_resize command."""
         self.spp_topo.resize_graph(args)
 
-    def do_topo(self, args):
-        """Output network topology.
-
-        Support four types of output.
-        * terminal (but very few terminals supporting to display images)
-        * browser (websocket server is required)
-        * image file (jpg, png, bmp)
-        * text (dot, js or json, yml or yaml)
-
-        spp > topo term  # terminal
-        spp > topo http  # browser
-        spp > topo network_conf.jpg  # image
-        spp > topo network_conf.dot  # text
-        spp > topo network_conf.js# text
-        """
+    def help_topo_resize(self):
+        """Print help message of topo command."""
+        topo.SppTopo.help_resize()
 
+    def do_topo(self, args):
+        """Output network topology."""
         self.spp_topo.run(args, self.get_sec_ids('nfv'))
 
+    def help_topo(self):
+        """Print help message of topo command."""
+        topo.SppTopo.help()
+
     def complete_topo(self, text, line, begidx, endidx):
 
         return self.spp_topo.complete(text, line, begidx, endidx)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [spp] [PATCH 09/10] controller: move status cmd help msg to help_msg
  2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
                   ` (7 preceding siblings ...)
  2019-06-24  7:11 ` [spp] [PATCH 08/10] controller: move topo " yasufum.o
@ 2019-06-24  7:11 ` yasufum.o
  2019-06-24  7:11 ` [spp] [PATCH 10/10] controller: move rest of " yasufum.o
  9 siblings, 0 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to move help message of status command to `help_msg`
module which is for defining a set of command name and message.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/help_msg.py | 10 ++++++++++
 src/controller/shell.py             | 15 ++++++++-------
 2 files changed, 18 insertions(+), 7 deletions(-)
 create mode 100644 src/controller/commands/help_msg.py

diff --git a/src/controller/commands/help_msg.py b/src/controller/commands/help_msg.py
new file mode 100644
index 0000000..9e15123
--- /dev/null
+++ b/src/controller/commands/help_msg.py
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+
+commands = {
+        'status':
+        """Display status info of SPP processes.
+
+        spp > status
+        """
+        }
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 54376c9..065fb07 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -10,6 +10,7 @@ from .commands import topo
 from .commands import vf
 from .commands import mirror
 from .commands import pcap
+from .commands import help_msg
 import os
 import re
 import readline
@@ -29,7 +30,7 @@ class Shell(cmd.Cmd, object):
         config_file = "{}/config/default.yml".format(
                 os.path.dirname(__file__))
         cli_config = yaml.load(open(config_file),
-                Loader=yaml.FullLoader)
+                               Loader=yaml.FullLoader)
     except IOError as e:
         print('Error: no config file found!')
         print(e)
@@ -205,7 +206,7 @@ class Shell(cmd.Cmd, object):
                 pt2 = id2.split(delim)[0]
                 if (pt1 in spp_common.PORT_TYPES) \
                         and (pt2 in spp_common.PORT_TYPES):
-                            return True
+                    return True
         return False
 
     def clean_cmd(self, cmdstr):
@@ -270,13 +271,13 @@ class Shell(cmd.Cmd, object):
         return res
 
     def do_status(self, _):
-        """Display status info of SPP processes
-
-        spp > status
-        """
-
+        """Display status info of SPP processes."""
         self.print_status()
 
+    def help_status(self):
+        """Print help message of status command."""
+        print(help_msg.commads['status'])
+
     def do_pri(self, command):
         """Send a command to primary process."""
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [spp] [PATCH 10/10] controller: move rest of help msg to help_msg
  2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
                   ` (8 preceding siblings ...)
  2019-06-24  7:11 ` [spp] [PATCH 09/10] controller: move status cmd help msg to help_msg yasufum.o
@ 2019-06-24  7:11 ` yasufum.o
  9 siblings, 0 replies; 11+ messages in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to move help message of rest of commands to `help_msg`.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/help_msg.py | 125 ++++++++++++++++++++-
 src/controller/shell.py             | 165 ++++++++++++----------------
 2 files changed, 194 insertions(+), 96 deletions(-)

diff --git a/src/controller/commands/help_msg.py b/src/controller/commands/help_msg.py
index 9e15123..f303547 100644
--- a/src/controller/commands/help_msg.py
+++ b/src/controller/commands/help_msg.py
@@ -1,10 +1,131 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
 
-commands = {
+cmds = {
         'status':
         """Display status info of SPP processes.
 
         spp > status
-        """
+        """,
+
+        'record':
+        """Save commands as a recipe file.
+
+        Save all of commands to a specified file as a recipe. This file
+        is reloaded with 'playback' command later. You can also edit
+        the recipe by hand to customize.
+
+        spp > record path/to/recipe_file
+        """,
+
+        'playback':
+        """Setup a network configuration from recipe file.
+
+        Recipe is a file describing a series of SPP command to setup
+        a network configuration.
+
+        spp > playback path/to/recipe_file
+        """,
+
+        'config':
+        """Show or update config.
+
+        # show list of config
+        spp > config
+
+        # set prompt to "$ spp "
+        spp > config prompt "$ spp "
+        """,
+
+        'pwd':
+        """Show corrent directory.
+
+        It behaves as UNIX's pwd command.
+
+        spp > pwd
+        """,
+
+        'ls':
+        """Show a list of specified directory.
+
+        It behaves as UNIX's ls command.
+
+        spp > ls path/to/dir
+        """,
+
+        'cd':
+        """Change current directory.
+
+        spp > cd path/to/dir
+        """,
+
+        'mkdir':
+        """Create a new directory.
+
+        It behaves as 'mkdir -p' which means that you can create sub
+        directories at once.
+
+        spp > mkdir path/to/dir
+        """,
+
+        'cat':
+        """View contents of a file.
+
+        spp > cat file
+        """,
+
+        'redo':
+        """Execute command of index of history.
+
+        spp > redo 5  # exec 5th command in the history
+        """,
+
+        'history':
+        """Show command history.
+
+        spp > history
+          1  ls
+          2  cat file.txt
+          ...
+
+        Command history is recorded in a file named '.spp_history'.
+        It does not add some command which are no meaning for history.
+        'bye', 'exit', 'history', 'redo'
+        """,
+
+        'less':
+        """View contents of a file.
+
+        spp > less file
+        """,
+
+        'exit':
+        """Terminate SPP controller process.
+
+        It is an alias of bye command to terminate controller.
+
+        spp > exit
+        Thank you for using Soft Patch Panel
+        """,
+
+        'inspect':
+        """Print attributes of Shell for debugging.
+
+        This command is intended to be used by developers to show the
+        inside of the object of Shell class.
+
+        spp > inspect
+        {'cmdqueue': [],
+         'completekey': 'tab',
+         'completion_matches': ['inspect'],
+         ...
+        """,
+
+        'load_cmd':
+        """Load command plugin.
+
+        Path of plugin file is 'spp/src/controller/plugins'.
+
+        spp > load_cmd hello
+        """,
         }
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 065fb07..3f4d95b 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -276,7 +276,7 @@ class Shell(cmd.Cmd, object):
 
     def help_status(self):
         """Print help message of status command."""
-        print(help_msg.commads['status'])
+        print(help_msg.cmds['status'])
 
     def do_pri(self, command):
         """Send a command to primary process."""
@@ -533,31 +533,22 @@ class Shell(cmd.Cmd, object):
                         self.get_sec_ids('pcap'), text, line, begidx, endidx)
 
     def do_record(self, fname):
-        """Save commands as a recipe file.
-
-        Save all of commands to a specified file as a recipe. This file
-        is reloaded with 'playback' command later. You can also edit
-        the recipe by hand to customize.
-
-        spp > record path/to/recipe_file
-        """
+        """Save commands as a recipe file."""
 
         if fname == '':
             print("Record file is required!")
         else:
             self.recorded_file = open(fname, 'w')
 
+    def help_record(self):
+        """Print help message of record command."""
+        print(help_msg.cmds['record'])
+
     def complete_record(self, text, line, begidx, endidx):
         return common.compl_common(text, line)
 
     def do_playback(self, fname):
-        """Setup a network configuration from recipe file.
-
-        Recipe is a file describing a series of SPP command to setup
-        a network configuration.
-
-        spp > playback path/to/recipe_file
-        """
+        """Setup a network configuration from recipe file."""
 
         if fname == '':
             print("Record file is required!")
@@ -575,18 +566,15 @@ class Shell(cmd.Cmd, object):
                 message = "Error: File does not exist."
                 print(message)
 
+    def help_playback(self):
+        """Print help message of playback command."""
+        print(help_msg.cmds['playback'])
+
     def complete_playback(self, text, line, begidx, endidx):
         return common.compl_common(text, line)
 
     def do_config(self, args):
-        """Show or update config.
-
-        # show list of config
-        spp > config
-
-        # set prompt to "$ spp "
-        spp > config prompt "$ spp "
-        """
+        """Show or update config."""
 
         tokens = args.strip().split(' ')
         if len(tokens) == 1:
@@ -620,6 +608,10 @@ class Shell(cmd.Cmd, object):
                 if key == 'prompt':
                     self.prompt = self.cli_config['prompt']['val']
 
+    def help_config(self):
+        """Print help message of config command."""
+        print(help_msg.cmds['config'])
+
     def complete_config(self, text, line, begidx, endidx):
         candidates = []
         tokens = line.strip().split(' ')
@@ -640,22 +632,15 @@ class Shell(cmd.Cmd, object):
         return completions
 
     def do_pwd(self, args):
-        """Show corrent directory.
-
-        It behaves as UNIX's pwd command.
-
-        spp > pwd
-        """
-
+        """Show corrent directory."""
         print(os.getcwd())
 
-    def do_ls(self, args):
-        """Show a list of specified directory.
+    def help_pwd(self):
+        """Print help message of pwd command."""
+        print(help_msg.cmds['pwd'])
 
-        It behaves as UNIX's ls command.
-
-        spp > ls path/to/dir
-        """
+    def do_ls(self, args):
+        """Show a list of specified directory."""
 
         if args == '' or os.path.isdir(args):
             c = 'ls -F %s' % args
@@ -663,14 +648,15 @@ class Shell(cmd.Cmd, object):
         else:
             print("No such a directory.")
 
+    def help_ls(self):
+        """Print help message of ls command."""
+        print(help_msg.cmds['ls'])
+
     def complete_ls(self, text, line, begidx, endidx):
         return common.compl_common(text, line)
 
     def do_cd(self, args):
-        """Change current directory.
-
-        spp > cd path/to/dir
-        """
+        """Change current directory."""
 
         if os.path.isdir(args):
             os.chdir(args)
@@ -678,21 +664,23 @@ class Shell(cmd.Cmd, object):
         else:
             print("No such a directory.")
 
+    def help_cd(self):
+        """Print help message of cd command."""
+        print(help_msg.cmds['cd'])
+
     def complete_cd(self, text, line, begidx, endidx):
         return common.compl_common(text, line, 'directory')
 
     def do_mkdir(self, args):
-        """Create a new directory.
-
-        It behaves as 'mkdir -p' which means that you can create sub
-        directories at once.
-
-        spp > mkdir path/to/dir
-        """
+        """Create a new directory."""
 
         c = 'mkdir -p %s' % args
         subprocess.call(c, shell=True)
 
+    def help_mkdir(self):
+        """Print help message of mkdir command."""
+        print(help_msg.cmds['mkdir'])
+
     def complete_mkdir(self, text, line, begidx, endidx):
         return common.compl_common(text, line)
 
@@ -718,21 +706,19 @@ class Shell(cmd.Cmd, object):
         return spp_bye.complete(text, line, begidx, endidx)
 
     def do_cat(self, arg):
-        """View contents of a file.
-
-        spp > cat file
-        """
+        """View contents of a file."""
         if os.path.isfile(arg):
             c = 'cat %s' % arg
             subprocess.call(c, shell=True)
         else:
             print("No such a directory.")
 
-    def do_redo(self, args):
-        """Execute command of index of history.
+    def help_cat(self):
+        """Print help message of cat command."""
+        print(help_msg.cmds['cat'])
 
-        spp > redo 5  # exec 5th command in the history
-        """
+    def do_redo(self, args):
+        """Execute command of index of history."""
 
         idx = int(args)
         cmdline = None
@@ -754,18 +740,12 @@ class Shell(cmd.Cmd, object):
         except IOError:
             print('Error: Cannot open history file "%s"' % self.hist_file)
 
-    def do_history(self, arg):
-        """Show command history.
-
-        spp > history
-          1  ls
-          2  cat file.txt
-          ...
+    def help_redo(self):
+        """Print help message of redo command."""
+        print(help_msg.cmds['redo'])
 
-        Command history is recorded in a file named '.spp_history'.
-        It does not add some command which are no meaning for history.
-        'bye', 'exit', 'history', 'redo'
-        """
+    def do_history(self, arg):
+        """Show command history."""
 
         try:
             f = open(self.hist_file)
@@ -785,53 +765,51 @@ class Shell(cmd.Cmd, object):
         except IOError:
             print('Error: Cannot open history file "%s"' % self.hist_file)
 
+    def help_history(self):
+        """Print help message of history command."""
+        print(help_msg.cmds['history'])
+
     def complete_cat(self, text, line, begidx, endidx):
         return common.compl_common(text, line)
 
     def do_less(self, arg):
-        """View contents of a file.
+        """View contents of a file."""
 
-        spp > less file
-        """
         if os.path.isfile(arg):
             c = 'less %s' % arg
             subprocess.call(c, shell=True)
         else:
             print("No such a directory.")
 
+    def help_less(self):
+        """Print help message of less command."""
+        print(help_msg.cmds['less'])
+
     def complete_less(self, text, line, begidx, endidx):
         return common.compl_common(text, line)
 
     def do_exit(self, args):
-        """Terminate SPP controller process.
-
-        It is an alias of bye command to terminate controller.
-
-        spp > exit
-        Thank you for using Soft Patch Panel
-        """
+        """Terminate SPP controller process."""
 
         self.close()
         print('Thank you for using Soft Patch Panel')
         return True
 
-    def do_inspect(self, args):
-        """Print attributes of Shell for debugging.
-
-        This command is intended to be used by developers to show the
-        inside of the object of Shell class.
+    def help_exit(self):
+        """Print help message of exit command."""
+        print(help_msg.cmds['exit'])
 
-        spp > inspect
-        {'cmdqueue': [],
-         'completekey': 'tab',
-         'completion_matches': ['inspect'],
-         ...
-        """
+    def do_inspect(self, args):
+        """Print attributes of Shell for debugging."""
 
         from pprint import pprint
         if args == '':
             pprint(vars(self))
 
+    def help_inspect(self):
+        """Print help message of inspect command."""
+        print(help_msg.cmds['inspect'])
+
     def terms_topo_subgraph(self):
         """Define terms of topo_subgraph command."""
 
@@ -927,12 +905,7 @@ class Shell(cmd.Cmd, object):
         return self.spp_topo.complete(text, line, begidx, endidx)
 
     def do_load_cmd(self, args):
-        """Load command plugin.
-
-        Path of plugin file is 'spp/src/controller/plugins'.
-
-        spp > load_cmd hello
-        """
+        """Load command plugin."""
 
         args = re.sub(',', ' ', args)
         args = re.sub(r'\s+', ' ', args)
@@ -947,6 +920,10 @@ class Shell(cmd.Cmd, object):
 
         print("Module '%s' loaded." % mod_name)
 
+    def help_load_cmd(self):
+        """Print help message of load_cmd command."""
+        print(help_msg.cmds['load_cmd'])
+
     def complete_load_cmd(self, text, line, begidx, endidx):
         """Complete command plugins
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-06-24  7:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24  7:11 [spp] [PATCH 00/10] Move help messages of CLI in shell.py yasufum.o
2019-06-24  7:11 ` [spp] [PATCH 01/10] controller: move vf help msg to SppVf.help yasufum.o
2019-06-24  7:11 ` [spp] [PATCH 02/10] controller: move server help msg to SppCtlServer yasufum.o
2019-06-24  7:11 ` [spp] [PATCH 03/10] controller: move pri help msg to SppPrimary yasufum.o
2019-06-24  7:11 ` [spp] [PATCH 04/10] controller: move nfv help msg to SppNfv yasufum.o
2019-06-24  7:11 ` [spp] [PATCH 05/10] controller: move mirror help msg to SppMirror yasufum.o
2019-06-24  7:11 ` [spp] [PATCH 06/10] controller: move pcap help msg to SppPcap yasufum.o
2019-06-24  7:11 ` [spp] [PATCH 07/10] controller: move bye help msg to SppBye yasufum.o
2019-06-24  7:11 ` [spp] [PATCH 08/10] controller: move topo " yasufum.o
2019-06-24  7:11 ` [spp] [PATCH 09/10] controller: move status cmd help msg to help_msg yasufum.o
2019-06-24  7:11 ` [spp] [PATCH 10/10] controller: move rest of " yasufum.o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).