diff frontends/src/jp/cmd_param.py @ 1589:add1a6c8c594

jp: optional positional arguments on "param get" command category and name are both optionals: - if nothing is given, categories list is printed - if only a category is given, a list of params and their values is printed - if both category and name are given, the requested param is printed
author Goffi <goffi@goffi.org>
date Sat, 14 Nov 2015 19:18:10 +0100
parents b8ee774c12c8
children 791c45ed8659
line wrap: on
line diff
--- a/frontends/src/jp/cmd_param.py	Sat Nov 14 19:18:10 2015 +0100
+++ b/frontends/src/jp/cmd_param.py	Sat Nov 14 19:18:10 2015 +0100
@@ -29,20 +29,35 @@
         super(Get, self).__init__(host, 'get', help=_('Get a parameter value'))
 
     def add_parser_options(self):
-        self.parser.add_argument("category", type=base.unicode_decoder, help=_(u"Category of the parameter"))
-        self.parser.add_argument("name", type=base.unicode_decoder, help=_(u"Name of the parameter"))
+        self.parser.add_argument("category", nargs='?', type=base.unicode_decoder, help=_(u"Category of the parameter"))
+        self.parser.add_argument("name", nargs='?', type=base.unicode_decoder, help=_(u"Name of the parameter"))
         self.parser.add_argument("-a", "--attribute", type=str, default="value", help=_(u"Name of the attribute to get"))
         self.parser.add_argument("--security-limit", type=int, default=-1, help=_(u"Security limit"))
 
     def connected(self):
         super(Get, self).connected()
+        if self.args.category is None:
+            categories = self.host.bridge.getParamsCategories()
+            print u"\n".join(categories)
+        elif self.args.name is None:
+            try:
+                values_dict = self.host.bridge.asyncGetParamsValuesFromCategory(self.args.category, self.args.security_limit, self.profile)
+            except Exception as e:
+                print u"Can't find requested parameters: {}".format(e)
+                self.host.quit(1)
+            for name, value in values_dict.iteritems():
+                print u"{}\t{}".format(name, value)
+        else:
+            try:
+                value = self.host.bridge.asyncGetParamA(self.args.name, self.args.category, self.args.attribute,
+                                                                  self.args.security_limit, self.profile)
+            except Exception as e:
+                print u"Can't find requested parameter: {}".format(e)
+                self.host.quit(1)
+            print value
+
+
         try:
-            value = self.host.bridge.asyncGetParamA(self.args.name, self.args.category, self.args.attribute,
-                                                              self.args.security_limit, self.profile)
-        except Exception:
-            print u"Can't find requested parameter"
-            self.host.quit(1)
-        print value
 
 
 class SaveTemplate(base.CommandBase):