|
1 | 1 | Help |
2 | 2 | ==== |
3 | 3 |
|
4 | | -use the categorize() function to create help categories |
| 4 | +From our experience, end users rarely read documentation no matter how high- |
| 5 | +quality or useful that documentation might be. So it is important that you |
| 6 | +provide good built-in help within your application. Fortunately, ``cmd2`` |
| 7 | +makes this easy. |
5 | 8 |
|
6 | | -Use ``help_method()`` to custom roll your own help messages. |
| 9 | +Getting Help |
| 10 | +------------ |
7 | 11 |
|
8 | | -See :ref:`features/argument_processing:Help Messages` |
| 12 | +``cmd2`` makes it easy for end users of ``cmd2`` applications to get help via |
| 13 | +the built-in ``help`` command. The ``help`` command by itself displays a list |
| 14 | +of the commands available: |
| 15 | + |
| 16 | +.. code-block:: text |
| 17 | +
|
| 18 | + (Cmd) help |
| 19 | +
|
| 20 | + Documented commands (use 'help -v' for verbose/'help <topic>' for details): |
| 21 | + =========================================================================== |
| 22 | + alias help ipy py run_pyscript set shortcuts |
| 23 | + edit history macro quit run_script shell |
| 24 | +
|
| 25 | +The ``help`` command can also be used to provide detailed help for a specific |
| 26 | +command: |
| 27 | + |
| 28 | +.. code-block:: text |
| 29 | +
|
| 30 | + (Cmd) help quit |
| 31 | + Usage: quit [-h] |
| 32 | +
|
| 33 | + Exit this application |
| 34 | +
|
| 35 | + optional arguments: |
| 36 | + -h, --help show this help message and exit |
| 37 | +
|
| 38 | +Providing Help |
| 39 | +-------------- |
| 40 | + |
| 41 | +``cmd2`` makes it easy for developers of ``cmd2`` applications to provide this |
| 42 | +help. By default, the help for a command is the docstring for the ``do_*`` |
| 43 | +method defining the command - e.g. for a command **foo**, that command is |
| 44 | +implementd by defining the ``do_foo`` method and the docstring for that method |
| 45 | +is the help. |
| 46 | + |
| 47 | +For commands which use one of the ``argparse`` decorators to parse arguments, |
| 48 | +help is provided by ``argparse``. See |
| 49 | +:ref:`features/argument_processing:Help Messages` for more information. |
| 50 | + |
| 51 | +Occasionally there might be an unusual circumstance where providing static help |
| 52 | +text isn't good enough and you want to provide dynamic information in the help |
| 53 | +text for a command. To meet this need, if a ``help_foo`` method is defined to |
| 54 | +match the ``do_foo`` method, then that method will be used to provide the help |
| 55 | +for command **foo**. This dynamic help is only supported for commands which |
| 56 | +do not use an ``argparse`` decorator because didn't want different output for |
| 57 | +``help cmd`` than for ``cmd -h``. |
9 | 58 |
|
10 | 59 | Categorizing Commands |
11 | 60 | --------------------- |
@@ -124,18 +173,21 @@ The ``help`` command also has a verbose option (``help -v`` or ``help |
124 | 173 |
|
125 | 174 | Other |
126 | 175 | ================================================================================ |
127 | | - alias Define or display aliases |
| 176 | + alias Manage aliases |
128 | 177 | config Config command |
129 | | - edit Edit a file in a text editor |
130 | | - help List available commands with "help" or detailed help with "help cmd" |
131 | | - history usage: history [-h] [-r | -e | -s | -o FILE | -t TRANSCRIPT] [arg] |
132 | | - py Invoke python command, shell, or script |
| 178 | + edit Run a text editor and optionally open a file with it |
| 179 | + help List available commands or provide detailed help for a specific command |
| 180 | + history View, run, edit, save, or clear previously entered commands |
| 181 | + macro Manage macros |
| 182 | + py Invoke Python command or shell |
133 | 183 | quit Exits this application |
134 | 184 | run_pyscript Runs a python script file inside the console |
135 | 185 | run_script Runs commands in script file that is encoded as either ASCII or UTF-8 text |
136 | | - set usage: set [-h] [-a] [-l] [settable [settable ...]] |
| 186 | + set Set a settable parameter or show current settings of parameters |
137 | 187 | shell Execute a command as if at the OS prompt |
138 | | - shortcuts Lists shortcuts available |
139 | | - unalias Unsets aliases |
| 188 | + shortcuts List available shortcuts |
140 | 189 | version Version command |
141 | 190 |
|
| 191 | +When called with the ``-v`` flag for verbose help, the one-line description for |
| 192 | +each command is provided by the first line of the docstring for that command's |
| 193 | +associated ``do_*`` method. |
0 commit comments