|
| 1 | +#!/usr/bin/env python |
| 2 | +# coding=utf-8 |
| 3 | +""" |
| 4 | +A sample application for tagging categories on commands. |
| 5 | +""" |
| 6 | + |
| 7 | +from cmd2 import Cmd, HELP_CATEGORY, __version__ |
| 8 | + |
| 9 | + |
| 10 | +class HelpCategories(Cmd): |
| 11 | + """ Example cmd2 application. """ |
| 12 | + |
| 13 | + # Command categories |
| 14 | + CMD_CAT_CONNECTING = 'Connecting' |
| 15 | + CMD_CAT_APP_MGMT = 'Application Management' |
| 16 | + CMD_CAT_SERVER_INFO = 'Server Information' |
| 17 | + |
| 18 | + def __init__(self): |
| 19 | + # Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell |
| 20 | + Cmd.__init__(self, use_ipython=False) |
| 21 | + |
| 22 | + def do_connect(self, _): |
| 23 | + """Connect command""" |
| 24 | + self.poutput('Connect') |
| 25 | + |
| 26 | + def do_which(self, _): |
| 27 | + """Which command""" |
| 28 | + self.poutput('Which') |
| 29 | + |
| 30 | + # Tag the above command functions under the category Connecting |
| 31 | + setattr(do_connect, HELP_CATEGORY, CMD_CAT_CONNECTING) |
| 32 | + setattr(do_which, HELP_CATEGORY, CMD_CAT_CONNECTING) |
| 33 | + |
| 34 | + def do_list(self, _): |
| 35 | + """List command""" |
| 36 | + self.poutput('List') |
| 37 | + |
| 38 | + def do_deploy(self, _): |
| 39 | + """Deploy command""" |
| 40 | + self.poutput('Which') |
| 41 | + |
| 42 | + def do_start(self, _): |
| 43 | + """Start command""" |
| 44 | + self.poutput('Start') |
| 45 | + |
| 46 | + def do_sessions(self, _): |
| 47 | + """Sessions command""" |
| 48 | + self.poutput('Sessions') |
| 49 | + |
| 50 | + def do_redeploy(self, _): |
| 51 | + """Redeploy command""" |
| 52 | + self.poutput('Redeploy') |
| 53 | + |
| 54 | + def do_restart(self, _): |
| 55 | + """Restart command""" |
| 56 | + self.poutput('Restart') |
| 57 | + |
| 58 | + def do_expire(self, _): |
| 59 | + """Expire command""" |
| 60 | + self.poutput('Expire') |
| 61 | + |
| 62 | + def do_undeploy(self, _): |
| 63 | + """Undeploy command""" |
| 64 | + self.poutput('Undeploy') |
| 65 | + |
| 66 | + def do_stop(self, _): |
| 67 | + """Stop command""" |
| 68 | + self.poutput('Stop') |
| 69 | + |
| 70 | + def do_findleakers(self, _): |
| 71 | + """Find Leakers command""" |
| 72 | + self.poutput('Find Leakers') |
| 73 | + |
| 74 | + # Tag the above command functions under the category Application Management |
| 75 | + setattr(do_list, HELP_CATEGORY, CMD_CAT_APP_MGMT) |
| 76 | + setattr(do_deploy, HELP_CATEGORY, CMD_CAT_APP_MGMT) |
| 77 | + setattr(do_start, HELP_CATEGORY, CMD_CAT_APP_MGMT) |
| 78 | + setattr(do_sessions, HELP_CATEGORY, CMD_CAT_APP_MGMT) |
| 79 | + setattr(do_redeploy, HELP_CATEGORY, CMD_CAT_APP_MGMT) |
| 80 | + setattr(do_restart, HELP_CATEGORY, CMD_CAT_APP_MGMT) |
| 81 | + setattr(do_expire, HELP_CATEGORY, CMD_CAT_APP_MGMT) |
| 82 | + setattr(do_undeploy, HELP_CATEGORY, CMD_CAT_APP_MGMT) |
| 83 | + setattr(do_stop, HELP_CATEGORY, CMD_CAT_APP_MGMT) |
| 84 | + setattr(do_findleakers, HELP_CATEGORY, CMD_CAT_APP_MGMT) |
| 85 | + |
| 86 | + def do_resources(self, _): |
| 87 | + """Resources command""" |
| 88 | + self.poutput('Resources') |
| 89 | + |
| 90 | + def do_status(self, _): |
| 91 | + """Status command""" |
| 92 | + self.poutput('Status') |
| 93 | + |
| 94 | + def do_serverinfo(self, _): |
| 95 | + """Server Info command""" |
| 96 | + self.poutput('Server Info') |
| 97 | + |
| 98 | + def do_thread_dump(self, _): |
| 99 | + """Thread Dump command""" |
| 100 | + self.poutput('Thread Dump') |
| 101 | + |
| 102 | + def do_sslconnectorciphers(self, _): |
| 103 | + """SSL Connector Ciphers command""" |
| 104 | + self.poutput('SSL Connector Ciphers') |
| 105 | + |
| 106 | + def do_vminfo(self, _): |
| 107 | + """VM Info command""" |
| 108 | + self.poutput('VM Info') |
| 109 | + |
| 110 | + # Tag the above command functions under the category Server Information |
| 111 | + setattr(do_resources, HELP_CATEGORY, CMD_CAT_SERVER_INFO) |
| 112 | + setattr(do_status, HELP_CATEGORY, CMD_CAT_SERVER_INFO) |
| 113 | + setattr(do_serverinfo, HELP_CATEGORY, CMD_CAT_SERVER_INFO) |
| 114 | + setattr(do_thread_dump, HELP_CATEGORY, CMD_CAT_SERVER_INFO) |
| 115 | + setattr(do_sslconnectorciphers, HELP_CATEGORY, CMD_CAT_SERVER_INFO) |
| 116 | + setattr(do_vminfo, HELP_CATEGORY, CMD_CAT_SERVER_INFO) |
| 117 | + |
| 118 | + # The following command functions don't have the HELP_CATEGORY attribute set |
| 119 | + # and show up in the 'Other' group |
| 120 | + def do_config(self, _): |
| 121 | + """Config command""" |
| 122 | + self.poutput('Config') |
| 123 | + |
| 124 | + def do_version(self, _): |
| 125 | + """Version command""" |
| 126 | + self.poutput(__version__) |
| 127 | + |
| 128 | + |
| 129 | +if __name__ == '__main__': |
| 130 | + c = HelpCategories() |
| 131 | + c.cmdloop() |
0 commit comments