示例#1
0
文件: commands.py 项目: nanguawu/parm
def call(prog_name, version, modules=None, args=None):
    from commands import execute_command_line
    
    modules = modules or []
    
    if isinstance(args, (unicode, str)):
        import shlex
        args = shlex.split(args)
    
    execute_command_line(args or sys.argv, get_commands(modules), prog_name, version)
示例#2
0
def call(prog_name, version, modules=None, args=None):
    from commands import execute_command_line

    modules = modules or []

    if isinstance(args, (unicode, str)):
        import shlex
        args = shlex.split(args)

    execute_command_line(args or sys.argv, get_commands(modules), prog_name,
                         version)
示例#3
0
文件: commands.py 项目: nanguawu/parm
                print_help(global_options)
        if global_options.help:
            print_help(global_options)
        else:
            command = self.fetch_command(global_options, subcommand)
            if issubclass(command, CommandManager):
                cmd = command(args[1:], None, '%s %s' % (self.prog_name, subcommand), global_options=global_options)
                cmd.execute()
            else:
                cmd = command()
                cmd.run_from_argv(self.prog_name, subcommand, global_options, args[1:])
    
class ApplicationCommandManager(CommandManager):
    option_list = (
        make_option('--help', action='store_true', dest='help',
            help='show this help message and exit.'),
        make_option('-v', '--verbose', action='store_true', 
            help='Output the result in verbose mode.'),
        make_option('--version', action='store_true', dest='version',
            help="show program's version number and exit."),
    )
    help = ''
    args = ''
    
def execute_command_line(argv=None, commands=None, prog_name=None, version=None):
    m = ApplicationCommandManager(argv, commands, prog_name, version=version)
    m.execute()
    
if __name__ == '__main__':
    execute_command_line(sys.argv)
示例#4
0
class ApplicationCommandManager(CommandManager):
    option_list = (
        make_option('--help',
                    action='store_true',
                    dest='help',
                    help='show this help message and exit.'),
        make_option('-v',
                    '--verbose',
                    action='store_true',
                    help='Output the result in verbose mode.'),
        make_option('--version',
                    action='store_true',
                    dest='version',
                    help="show program's version number and exit."),
    )
    help = ''
    args = ''


def execute_command_line(argv=None,
                         commands=None,
                         prog_name=None,
                         version=None):
    m = ApplicationCommandManager(argv, commands, prog_name, version=version)
    m.execute()


if __name__ == '__main__':
    execute_command_line(sys.argv)