From 8e4180237f374a2ef80f73c9e1731ea0b013ee3a Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 14 Nov 2015 19:18:10 +0100 Subject: [PATCH] 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 --- frontends/src/jp/cmd_param.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/frontends/src/jp/cmd_param.py b/frontends/src/jp/cmd_param.py index ea3723b5..d22e9ca7 100644 --- a/frontends/src/jp/cmd_param.py +++ b/frontends/src/jp/cmd_param.py @@ -29,20 +29,35 @@ class Get(base.CommandBase): 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):