def __description(self, parser): """ Get the description of the module, for inclusion in usage information. """ description = self.__class__.description + "\n\n" description = description + "Examples:\n" + self.__class__.examples + "\n\n" description = description + "Last Modified: " + self.__class__.date + "\n" if isinstance(self.__class__.author, str): description = description + "Credit: " + self.__class__.author + "\n" else: description = description + "Credit: " + ", ".join(self.__class__.author) + "\n" description = description + "License: " + self.__class__.license + "\n\n" return wrap(description, width=console.getSize()[0])
def do_list(self, args): """ usage: list [FILTER] Displays a list of the available modules, optionally filtered by name. Examples: mercury> list activity.forintent activity.info ... snip ... mercury> list debug information.debuggable mercury> """ argv = shlex.split(args, comments=True) if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"): self.do_help("list") return term = len(argv) > 0 and argv[0] or None # recalculate the sizing, depending on the size of the user's terminal window width = { 'gutter': 2, 'total': console.getSize()[0] } width['label'] = width['total'] / 3 width['desc'] = width['total'] - (width['gutter'] + width['label']) for module in filter(lambda m: term == None or m.find(term.lower()) >= 0, self.__modules()): name = wrap(Module.get(module).name, width['desc']).split("\n") if len(module[len(self.__base):]) > width['label']: self.stdout.write(("{:<%d}\n" % width['label']).format(module[len(self.__base):])) self.stdout.write(("{:<%d} {:<%d}\n" % (width['label'], width['desc'])).format("", name.pop(0))) else: self.stdout.write(("{:<%d} {:<%d}\n" % (width['label'], width['desc'])).format(module[len(self.__base):], name.pop(0))) for line in name: self.stdout.write(("{:<%d} {:<%d}\n" % (width['label'], width['desc'])).format("", line))
def do_help(self, args): """ usage: help [COMMAND OR MODULE] Displays help information. """ argv = shlex.split(args, comments=True) if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"): self.do_help("help") return if len(argv) > 0: if self.__module_name(argv[0]) in Module.all() or self.__module_name("." + argv[0]) in Module.all(): self.do_run(" ".join([argv[0], "--help"])) else: try: func = getattr(self, 'help_' + argv[0]) except AttributeError: try: doc = getattr(self, 'do_' + argv[0]).__doc__ if doc: self.stdout.write("%s\n" % wrap(textwrap.dedent(str(doc)).strip(), width=console.getSize()[0])) return except AttributeError: pass self.stdout.write("%s\n" % str(self.nohelp) % (argv[0],)) return func() else: cmd.Cmd.do_help(self, args)