def do_help(self, arg): """Command to display help info""" self.stdout.write("\n%s Namespace Help\n" % self.namespace) # If we're just in the cmd2 namespace, return its help if (self.namespace == 'cmd2'): Cmd.do_help(arg) return else: # Else, if we're in another namespace, try the following: if arg: # If getting help for a specific command in the namespace, try: # First see if the namespace command exists try: do_func = getattr(self, 'do_' + self.namespace + "_" + arg) except AttributeError: # Namespace function doesn't exist - see if there is a non-namespace / cmd2 command with arg name try: do_func = getattr(self, 'do_' + arg) Cmd.do_help(arg) return except AttributeError: self.stdout.write("[ERROR] Command does not exist in this or top-level namespace: %s\n" % arg) return try: # Next see if there is a help_<namespace>_<command> method is available to call help_func = getattr(self, 'help_' + self.namespace + '_' + arg) help_func() return except AttributeError: # If no help method for the command, get the __doc__ for the method if exists try: doc=getattr(self, 'do_' + self.namespace + '_' + arg).__doc__ if doc: self.stdout.write("%s\n" % str(doc)) return except AttributeError: self.stdout.write("%s\n"%str(self.nohelp % (arg,))) return # Otherwise display generic help else: #names = self.get_names() + self.get_names_addendum names = self.get_names() cmds_doc = [] cmds_undoc = [] cmds_cmd2_namespace = [] for name in names: if name.startswith('do_' + self.namespace): cmd_prefix_length = len(self.namespace)+4 cmd=name[cmd_prefix_length:] if getattr(self, name).__doc__: cmds_doc.append(cmd) else: cmds_undoc.append(cmd) elif name[:3] == 'do_': cmd=name[3:] cmds_cmd2_namespace.append(cmd) self.stdout.write("%s\n" % str(self.doc_leader)) self.print_topics(self.doc_header, cmds_doc, 15,80) self.print_topics(self.undoc_header, cmds_undoc, 15,80) self.print_topics("'cmd2' Namespace Commands", cmds_cmd2_namespace, 15, 80)
def do_help(self, arg): """List available commands with "help" or detailed help with "help cmd".""" tmp = self.get_names self.get_names = self.get_names_hack # Ugly hack: I'm to lazy to reimplement whole do_help ;-) Cmd.do_help(self, arg) self.get_names = tmp if arg == "": self.print_topics( "\n[ " + various.colorize("red", "Important commands") + " ]\n", [x[3:] for x in self.important_commands], 15, 80 ) print("\n[ " + various.colorize("red", "Example usage") + " ]\n" + consts.example_usage)
def do_help(self, s): if s == '': print("FENRIR Commands :") print("\tcookie") print("\tcreate_virtual_tap") print("\tdestroy_virtual_tap") print("\tadd_reverse_rule") print("\trun") print("\trun_debug") print("\tset") print("\tshell") print("\tshortcuts") print("\tautoconf") print("\tstop") print("\tquit") print("\thelp") else: Cmd.do_help(self, s)
def do_help(self, arg): """Command to display help info""" self.stdout.write("\n%s Namespace Help\n" % self.namespace) # If we're just in the cmd2 namespace, return its help if (self.namespace == 'cmd2'): Cmd.do_help(arg) return else: # Else, if we're in another namespace, try the following: if arg: # If getting help for a specific command in the namespace, try: # First see if the namespace command exists try: do_func = getattr(self, 'do_' + self.namespace + "_" + arg) except AttributeError: # Namespace function doesn't exist - see if there is a non-namespace / cmd2 command with arg name try: do_func = getattr(self, 'do_' + arg) Cmd.do_help(arg) return except AttributeError: self.stdout.write( "[ERROR] Command does not exist in this or top-level namespace: %s\n" % arg) return try: # Next see if there is a help_<namespace>_<command> method is available to call help_func = getattr(self, 'help_' + self.namespace + '_' + arg) help_func() return except AttributeError: # If no help method for the command, get the __doc__ for the method if exists try: doc = getattr(self, 'do_' + self.namespace + '_' + arg).__doc__ if doc: self.stdout.write("%s\n" % str(doc)) return except AttributeError: self.stdout.write("%s\n" % str(self.nohelp % (arg, ))) return # Otherwise display generic help else: #names = self.get_names() + self.get_names_addendum names = self.get_names() cmds_doc = [] cmds_undoc = [] cmds_cmd2_namespace = [] for name in names: if name.startswith('do_' + self.namespace): cmd_prefix_length = len(self.namespace) + 4 cmd = name[cmd_prefix_length:] if getattr(self, name).__doc__: cmds_doc.append(cmd) else: cmds_undoc.append(cmd) elif name[:3] == 'do_': cmd = name[3:] cmds_cmd2_namespace.append(cmd) self.stdout.write("%s\n" % str(self.doc_leader)) self.print_topics(self.doc_header, cmds_doc, 15, 80) self.print_topics(self.undoc_header, cmds_undoc, 15, 80) self.print_topics("'cmd2' Namespace Commands", cmds_cmd2_namespace, 15, 80)