# HG changeset patch # User Goffi # Date 1447525090 -3600 # Node ID add1a6c8c594c23a91b5888d61f000b1cf9b099b # Parent 823a385235ef1c15674f7aa1893d11520f9605f3 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 diff -r 823a385235ef -r add1a6c8c594 frontends/src/jp/cmd_param.py --- 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):