示例#1
0
def describe(usage="command:\n", out=sys.stdout, package=None, name=None, level=1, scan=COLLECTOR.scan):
    if name is None:
        frame = sys._getframe(level)
        name = frame.f_globals["__name__"]
        package = frame.f_globals["__package__"]

    if name == "__main__":
        parser = argparse.ArgumentParser()
        parser.add_argument("-f", "--full", default=False, action="store_true", dest="full_description")
        args = parser.parse_args()
        commands = list(sorted(scan(package), key=lambda x: x.name))

        write(out, "avaiable commands are here. (with --full option, showing full text)\n\n")
        for command in commands:
            if command.short_description:
                write(out, u"- {} -- {}\n".format(command.name, command.short_description))
            else:
                write(out, u"- {}\n".format(command.name))

        if args.full_description and commands:
            write(out, u"\n")
            for command in commands:
                write(out, u"\n---{}-------------------------------------\n".format(command.name))
                command.print_help(out)
示例#2
0
 def __call__(self, parser, namespace, val, option_string=None):
     json_data = json.dumps(self.generate_dict(parser), indent=2, sort_keys=True)
     write(sys.stdout, json_data)
     parser.exit()