argparse和extras的声明性接口。
commando的Python项目详细描述
1.0.0版
argparse的一个简单包装器,它允许命令和参数 使用decorators以声明方式定义。请注意,这是 还不支持argparse的所有功能。
突击队还捆绑了一些在建造时有用的实用程序 命令行应用程序。
示例
没有突击队:
def main(): parser = argparse.ArgumentParser(description='hyde - a python static website generator', epilog='Use %(prog)s {command} -h to get help on individual commands') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__) parser.add_argument('-s', '--sitepath', action='store', default='.', help="Location of the hyde site") subcommands = parser.add_subparsers(title="Hyde commands", description="Entry points for hyde") init_command = subcommands.add_parser('init', help='Create a new hyde site') init_command.set_defaults(run=init) init_command.add_argument('-t', '--template', action='store', default='basic', dest='template', help='Overwrite the current site if it exists') init_command.add_argument('-f', '--force', action='store_true', default=False, dest='force', help='Overwrite the current site if it exists') args = parser.parse_args() args.run(args) def init(self, params): print params.sitepath print params.template print params.overwrite
使用突击队:
class Engine(Application): @command(description='hyde - a python static website generator', epilog='Use %(prog)s {command} -h to get help on individual commands') @param('-v', '--version', action='version', version='%(prog)s ' + __version__) @param('-s', '--sitepath', action='store', default='.', help="Location of the hyde site") def main(self, params): pass @subcommand('init', help='Create a new hyde site') @param('-t', '--template', action='store', default='basic', dest='template', help='Overwrite the current site if it exists') @param('-f', '--force', action='store_true', default=False, dest='overwrite', help='Overwrite the current site if it exists') def init(self, params): print params.sitepath print params.template print params.overwrite