From d5985803391a50937c352a663373c3bb15cc927d Mon Sep 17 00:00:00 2001
From: Seblu <sebastien.luttringer@smartjog.com>
Date: Mon, 14 Feb 2011 19:51:31 +0100
Subject: [PATCH] addacount now take a password argument and so use TqlCommand

---
 cccli/command/account.py | 22 ++++++++++++++++------
 cccli/command/command.py | 12 ++++++++++--
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/cccli/command/account.py b/cccli/command/account.py
index a95249d..52d268f 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 1b40c26..f48e76f 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:
-- 
GitLab