Commit e3cd9651 authored by Seblu's avatar Seblu
Browse files

add a new OptionCommand class which add option parser to command class

parent d320e341
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@ class Command_addaccount(Command):
            raise cmdError("RPCError: %s"%str(e))

    def usage(self):
        return "usage: addaccount <account name> <role>"
        return "Usage: addaccount <account name> <role>"


class Command_delaccount(Command):
    '''Delete an account'''
@@ -36,7 +37,7 @@ class Command_delaccount(Command):
            raise cmdError("RPCError: %s"%str(e))

    def usage(self):
        return "usage: delaccount <tql>"
        return "Usage: delaccount <tql>"


class Command_close(Command):
@@ -51,7 +52,7 @@ class Command_close(Command):
            raise cmdError("RPCError: %s"%str(e))

    def usage(self):
        return "usage: close <tql>"
        return "Usage: close <tql>"


class Command_declose(Command):
@@ -67,7 +68,7 @@ class Command_declose(Command):
            raise cmdError("RPCError: %s"%str(e))

    def usage(self):
        return "usage: declose <tql>"
        return "Usage: declose <tql>"


class Command_passwd(Command):
@@ -95,4 +96,4 @@ class Command_passwd(Command):
            raise cmdError("RPCError: %s"%str(e))

    def usage(self):
        return "usage: passwd [tql] [password]"
        return "Usage: passwd [tql] [password]"
+5 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ from cccli.command.command import Command

class Command_alias(Command):
    '''Show or create alias'''

    def __call__(self, argv):
        if len(argv) == 1:
            for n, v in self.cli.alias.items():
@@ -25,10 +26,12 @@ class Command_alias(Command):
            raise cmdBadArgument()

    def usage(self):
         return "usage: alias [name] [value]"
         return "Usage: alias [name] [value]"


class Command_unalias(Command):
    '''Remove an alias'''

    def __call__(self, argv):
        if len(argv) != 2:
            raise cmdBadArgument()
@@ -38,4 +41,4 @@ class Command_unalias(Command):
        self.cli.alias.save(self.cli.settings.get("alias", ""))

    def usage(self):
        return "usage: unalias [name]"
        return "Usage: unalias [name]"
+18 −2
Original line number Diff line number Diff line
@@ -5,14 +5,30 @@
CloudControl CLI command module
'''

from optparse import OptionParser

class Command(object):

    def __init__(self, cli):
    def __init__(self, cli, argv0):
        self.cli = cli
        self.printer = self.cli.printer
        self.name = argv0

    def usage(self):
        return "Usage: %s"%self.name

    def help(self):
        return self.__doc__


class OptionCommand(Command):

    def __init__(self, cli, argv0):
        Command.__init__(self, cli, argv0)
        self.option = OptionParser(prog=argv0)

    def usage(self):
        return None
        return self.option.format_help().strip()

    def help(self):
        return self.__doc__
+2 −5
Original line number Diff line number Diff line
@@ -26,7 +26,8 @@ class Command_uptime(Command):
                self.printer.out("%s: %ss"%(o["a"], o["con"]))

    def usage(self):
        return "usage: uptime [tql]"
        return "Usage: uptime [tql]"


class Command_remote(Command):
    '''Show remote command list'''
@@ -38,8 +39,6 @@ class Command_remote(Command):
        except RpcError as e:
            raise cmdError("RPCError: %s"%str(e))

    def usage(self):
        return "usage: remote"

class Command_whoami(Command):
    '''Show connection login'''
@@ -47,8 +46,6 @@ class Command_whoami(Command):
    def __call__(self, argv):
        self.printer.out(self.cli.settings["login"])

    def usage(self):
        return "usage: whoami"

class Command_kill(Command):
    '''Kill a server connection'''
+2 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ class Command_exec(Command):
            raise cmdError("RPCError: %s"%str(e))

    def usage(self):
        return "usage: exec <tql> <command>"
        return "Usage: exec <tql> <command>"

class Command_shutdown(Command):
    '''Shutdown a physical host'''
@@ -32,4 +32,4 @@ class Command_shutdown(Command):
            raise cmdError("RPCError: %s"%str(e))

    def usage(self):
        return "usage: shutdown <tql>"
        return "Usage: shutdown <tql>"
Loading