Loading cccli/cli.py +6 −3 Original line number Diff line number Diff line Loading @@ -122,14 +122,17 @@ class Cli(object): # execute command Command(argv, self).call() except BadArgument, e: if str(e) != "": if str(e): printer.error("Bad argument: %s."%str(e)) else: printer.error("Bad argument.") usage = Command.usage(argv[0]) if usage != "": printer.out("usage: %s."%usage) except BadCommand: except BadCommand, e: if str(e): printer.error("command: %s."%str(e)) else: printer.error("No command: %s."%argv[0]) except sjrpc.core.exceptions.RpcError, e: if cccli.debug: raise Loading cccli/command.py +15 −0 Original line number Diff line number Diff line Loading @@ -10,8 +10,23 @@ from cccli.clierror import * class Command(object): def __init__(self, argv, cli): # check argv if len(argv) < 1: raise BadCommand() # check valid command chars if not re.match("^[a-zA-Z0-9]+", argv[0]): raise BadCommmand("Invalid command name") cmdlist = [ x[4:] for x in dir(self) if x.startswith("cmd_") ] matchlist = [ x for x in cmdlist if re.match("%s.+"%argv[0], x) ] if argv[0] in cmdlist: pass elif len(matchlist) == 1: argv[0] = matchlist[0] elif len(matchlist) > 1: raise BadCommand("Too many command: %s"%", ".join(matchlist)) else: raise BadCommand() self._cmd = getattr(self, "cmd_%s"%argv[0]) self._argv = argv self.cli = cli Loading Loading
cccli/cli.py +6 −3 Original line number Diff line number Diff line Loading @@ -122,14 +122,17 @@ class Cli(object): # execute command Command(argv, self).call() except BadArgument, e: if str(e) != "": if str(e): printer.error("Bad argument: %s."%str(e)) else: printer.error("Bad argument.") usage = Command.usage(argv[0]) if usage != "": printer.out("usage: %s."%usage) except BadCommand: except BadCommand, e: if str(e): printer.error("command: %s."%str(e)) else: printer.error("No command: %s."%argv[0]) except sjrpc.core.exceptions.RpcError, e: if cccli.debug: raise Loading
cccli/command.py +15 −0 Original line number Diff line number Diff line Loading @@ -10,8 +10,23 @@ from cccli.clierror import * class Command(object): def __init__(self, argv, cli): # check argv if len(argv) < 1: raise BadCommand() # check valid command chars if not re.match("^[a-zA-Z0-9]+", argv[0]): raise BadCommmand("Invalid command name") cmdlist = [ x[4:] for x in dir(self) if x.startswith("cmd_") ] matchlist = [ x for x in cmdlist if re.match("%s.+"%argv[0], x) ] if argv[0] in cmdlist: pass elif len(matchlist) == 1: argv[0] = matchlist[0] elif len(matchlist) > 1: raise BadCommand("Too many command: %s"%", ".join(matchlist)) else: raise BadCommand() self._cmd = getattr(self, "cmd_%s"%argv[0]) self._argv = argv self.cli = cli Loading