@@ -237,3 +237,165 @@ set_window_title()
237237The easiest way to understand these functions is to see the AsyncPrinting _ example for a demonstration.
238238
239239.. _AsyncPrinting : https://github.com/python-cmd2/cmd2/blob/master/examples/async_printing.py
240+
241+
242+ Grouping Commands
243+ =================
244+
245+ By default, the ``help `` command displays::
246+
247+ Documented commands (type help <topic>):
248+ ========================================
249+ alias findleakers pyscript sessions status vminfo
250+ config help quit set stop which
251+ connect history redeploy shell thread_dump
252+ deploy list resources shortcuts unalias
253+ edit load restart sslconnectorciphers undeploy
254+ expire py serverinfo start version
255+
256+ If you have a large number of commands, you can optionally group your commands into categories.
257+ Here's the output from the example ``help_categories.py ``::
258+
259+ Documented commands (type help <topic>):
260+
261+ Application Management
262+ ======================
263+ deploy findleakers redeploy sessions stop
264+ expire list restart start undeploy
265+
266+ Connecting
267+ ==========
268+ connect which
269+
270+ Server Information
271+ ==================
272+ resources serverinfo sslconnectorciphers status thread_dump vminfo
273+
274+ Other
275+ =====
276+ alias edit history py quit shell unalias
277+ config help load pyscript set shortcuts version
278+
279+
280+ There are 2 methods of specifying command categories, using the ``@with_category `` decorator or with the
281+ ``categorize() `` function. Once a single command category is detected, the help output switches to a categorized
282+ mode of display. All commands with an explicit category defined default to the category `Other `.
283+
284+ Using the ``@with_category `` decorator::
285+
286+ @with_category(CMD_CAT_CONNECTING)
287+ def do_which(self, _):
288+ """Which command"""
289+ self.poutput('Which')
290+
291+ Using the ``categorize() `` function:
292+
293+ You can call with a single function::
294+
295+ def do_connect(self, _):
296+ """Connect command"""
297+ self.poutput('Connect')
298+
299+ # Tag the above command functions under the category Connecting
300+ categorize(do_connect, CMD_CAT_CONNECTING)
301+
302+ Or with an Iterable container of functions::
303+
304+ def do_undeploy(self, _):
305+ """Undeploy command"""
306+ self.poutput('Undeploy')
307+
308+ def do_stop(self, _):
309+ """Stop command"""
310+ self.poutput('Stop')
311+
312+ def do_findleakers(self, _):
313+ """Find Leakers command"""
314+ self.poutput('Find Leakers')
315+
316+ # Tag the above command functions under the category Application Management
317+ categorize((do_undeploy,
318+ do_stop,
319+ do_findleakers), CMD_CAT_APP_MGMT)
320+
321+ The ``help `` command also has a verbose option (``help -v `` or ``help --verbose ``) that combines
322+ the help categories with per-command Help Messages::
323+
324+ Documented commands (type help <topic>):
325+
326+ Application Management
327+ ================================================================================
328+ deploy Deploy command
329+ expire Expire command
330+ findleakers Find Leakers command
331+ list List command
332+ redeploy Redeploy command
333+ restart usage: restart [-h] {now,later,sometime,whenever}
334+ sessions Sessions command
335+ start Start command
336+ stop Stop command
337+ undeploy Undeploy command
338+
339+ Connecting
340+ ================================================================================
341+ connect Connect command
342+ which Which command
343+
344+ Server Information
345+ ================================================================================
346+ resources Resources command
347+ serverinfo Server Info command
348+ sslconnectorciphers SSL Connector Ciphers command is an example of a command that contains
349+ multiple lines of help information for the user. Each line of help in a
350+ contiguous set of lines will be printed and aligned in the verbose output
351+ provided with 'help --verbose'
352+ status Status command
353+ thread_dump Thread Dump command
354+ vminfo VM Info command
355+
356+ Other
357+ ================================================================================
358+ alias Define or display aliases
359+ config Config command
360+ edit Edit a file in a text editor
361+ help List available commands with "help" or detailed help with "help cmd"
362+ history usage: history [-h] [-r | -e | -s | -o FILE | -t TRANSCRIPT] [arg]
363+ load Runs commands in script file that is encoded as either ASCII or UTF-8 text
364+ py Invoke python command, shell, or script
365+ pyscript Runs a python script file inside the console
366+ quit Exits this application
367+ set usage: set [-h] [-a] [-l] [settable [settable ...]]
368+ shell Execute a command as if at the OS prompt
369+ shortcuts Lists shortcuts available
370+ unalias Unsets aliases
371+ version Version command
372+
373+
374+ Disabling Commands
375+ ==================
376+
377+ ``cmd2 `` supports disabling commands during runtime. This is useful if certain commands should only be available
378+ when the application is in a specific state. When a command is disabled, it will not show up in the help menu or
379+ tab complete. If a user tries to run the command, a command-specific message supplied by the developer will be
380+ printed. The following functions support this feature.
381+
382+ enable_command()
383+ Enable an individual command
384+
385+ enable_category()
386+ Enable an entire category of commands
387+
388+ disable_command()
389+ Disable an individual command and set the message that will print when this command is run or help is called
390+ on it while disabled
391+
392+ disable_category()
393+ Disable an entire category of commands and set the message that will print when anything in this category is
394+ run or help is called on it while disabled
395+
396+ See the definitions of these functions for descriptions of their arguments.
397+
398+ See the ``do_enable_commands() `` and ``do_disable_commands() `` functions in the HelpCategories _ example for
399+ a demonstration.
400+
401+ .. _HelpCategories : https://github.com/python-cmd2/cmd2/blob/master/examples/help_categories.py
0 commit comments