diff --git a/cccli/command/account.py b/cccli/command/account.py index a95249d0742539668ca0f34344e96580c372d5fd..52d268f632ccf561ebf98dd9b1746293902b04b5 100644 --- a/cccli/command/account.py +++ b/cccli/command/account.py @@ -10,20 +10,30 @@ from sjrpc.core.exceptions import * from cccli.printer import Printer, color from cccli.command.command import OptionCommand, TqlCommand -class Command_addaccount(OptionCommand): +class Command_addaccount(TqlCommand): '''Create an account''' def __init__(self, cli, argv0): - OptionCommand.__init__(self, cli, argv0) - self.set_usage("%prog [options] <account name> <role>") + TqlCommand.__init__(self, cli, argv0) + self.set_usage("%prog [options] <account name> <role> [password]") def __call__(self, argv): # parse args self.parse_args(argv) - if len(self.args) != 2: + if len(self.args) == 2: + _pass = None + elif len(self.args) == 3: + _pass = self.args[2] + if self.printer.isinteractive(): + self.printer.warn("Removing last line from history") + self.printer.history.removelast() + else: raise cmdBadArgument() - # execute command - self.rpccall("addaccount", self.args[0], self.args[1]) + # add account + self.rpccall("addaccount", self.args[0], self.args[1], _status=False) + # set password + if _pass is not None: + self.rpccall("passwd", "a=%s"%self.args[0], _pass) class Command_delaccount(TqlCommand): diff --git a/cccli/command/command.py b/cccli/command/command.py index 1b40c26e2b28baa01e38b72dc8f49846b2101787..f48e76f87405d2f80445afd9720d16a0f58d8e2a 100644 --- a/cccli/command/command.py +++ b/cccli/command/command.py @@ -94,15 +94,23 @@ class TqlCommand(OptionCommand): def rpccall(self, *args, **kwargs): '''Call a RPC method an show tql return''' + # check for status printing + if "_status" in kwargs: + _status = kwargs["_status"] + del kwargs["_status"] + elif self.options.status: + _status = True + else: + _status = False + # Do RPC Call try: d = self.rpc.call(*args, **kwargs) - if self.options.status: + if _status: self.show_status(d) return d except RpcError as e: raise cmdError("RPCError: %s"%str(e)) - def show_status(self, ans): '''Show status of an Tql request''' try: