def run(self, options, args): def load_subcommand(command, top_level_path): path = [os.path.join(top_level_path, command)] for _, cmd, __ in walk_packages(path=path): subcmd = '{0}.{1}'.format(command, cmd) load_command(subcmd) self.subcommands[subcmd] = commands[subcmd].summary if args: cmd = args[0].lower() load_command(cmd) if cmd not in commands: self.parser.error('No command named: {0}'.format(cmd)) commands[cmd].help() return 0 # Load all available commands for imp, command, ispkg in walk_packages(path=cmds.__path__): load_command(command) try: self.subcommands[command] = commands[command].summary except KeyError: pass if ispkg: load_subcommand(command, cmds.__path__[0]) self.help() return 0
def run(self, options, args): def load_subcommand(command, top_level_path): path = [os.path.join(top_level_path, command)] for _, cmd, __ in walk_packages(path=path): subcmd = '{0}.{1}'.format(command, cmd) load_command(subcmd) self.subcommands[subcmd] = commands[subcmd].summary if args: cmd = args[0].lower() load_command(cmd) if cmd not in commands: self.parser.error('No command named: {0}'.format(cmd)) commands[cmd].help() return 0 # Load all available commands for imp, command, ispkg in walk_packages(path=cmds.__path__): if ispkg: load_subcommand(command, cmds.__path__[0]) else: load_command(command) self.subcommands[command] = commands[command].summary self.help() return 0
def main(): opts, args = main_parser.parse_args() if opts.help and not args: args = ['help'] if not args: main_parser.error('You must provide a command. ' '(Use `gh help` to see a list of commands)') repository = () if opts.repository and '/' in opts.repository: repository = opts.repository.split('/', 1) if opts.loc_aware and not repository: repository = get_repository_tuple() command = args[0].lower() load_command(command) status = 1 if command in commands: commands[command].repository = repository status = commands[command].run(opts, args[1:]) if status == commands[command].COMMAND_UNKNOWN: print('Unknown subcommand or option.') commands[command].help() sys.exit(status)
def main(): opts, args = main_parser.parse_args() if opts.help and not args: args = ['help'] if not args: main_parser.error('You must give a command. ' '(Use `gh help` to see a list of commands)') repository = () if opts.repository and '/' in opts.repository: repository = opts.repository.split('/', 1) if opts.loc_aware and not repository: repository = get_repository_tuple() command = args[0].lower() load_command(command) status = 1 if command in commands: commands[command].repository = repository status = commands[command].run(opts, args[1:]) if status == commands[command].COMMAND_UNKNOWN: print('Unknown subcommand or option.') commands[command].help() else: main_parser.error('No such command "{0}"'.format(command)) sys.exit(status)
def test_commands(self): assert self.command not in commands load_command(self.command) error = '{0} not in commands dict'.format(self.command) assert self.command in commands, error
def test_load_command(self): load_command(self.command) assert self.mod in sys.modules load_command('foobarbogus') assert 'gh.commands.foobarbogus' not in sys.modules
def load_subcommand(command, top_level_path): path = [os.path.join(top_level_path, command)] for _, cmd, __ in walk_packages(path=path): subcmd = '{0}.{1}'.format(command, cmd) load_command(subcmd) self.subcommands[subcmd] = commands[subcmd].summary