# HG changeset patch # User Goffi # Date 1522509043 -7200 # Node ID 2d69a0afe039d741a0ffab4898990612dd2fbf37 # Parent 48820e4a1f8a2243d5950dedb60a5d5b2145a345 jp: new argument pubsub_default can be used in Commands to replace default value in help string diff -r 48820e4a1f8a -r 2d69a0afe039 frontends/src/jp/base.py --- a/frontends/src/jp/base.py Fri Mar 30 19:49:35 2018 +0200 +++ b/frontends/src/jp/base.py Sat Mar 31 17:10:43 2018 +0200 @@ -324,10 +324,13 @@ draft_group.add_argument("-F", "--draft-path", type=unicode_decoder, help=_(u"path to a draft file to retrieve")) - def make_pubsub_group(self, flags): + def make_pubsub_group(self, flags, defaults): """generate pubsub options according to flags @param flags(iterable[unicode]): see [CommandBase.__init__] + @param defaults(dict[unicode, unicode]): help text for default value + key can be "service" or "node" + value will be set in " (DEFAULT: {value})", or can be None to remove DEFAULT @return (ArgumentParser): parser to add """ flags = misc.FlagsHandler(flags) @@ -338,13 +341,17 @@ service_help = _(u"JID of the PubSub service") if not flags.service: - service_help += _(u" (default: PEP service)") + default = defaults.pop(u'service', _(u'PEP service')) + if default is not None: + service_help += _(u" (DEFAULT: {default})".format(default=default)) pubsub_group.add_argument("-s", "--service", type=unicode_decoder, default=u'', help=service_help) node_help = _(u"node to request") if not flags.node: - node_help += _(u" (DEFAULT: standard node)") + default = defaults.pop(u'node', _(u'standard node')) + if default is not None: + node_help += _(u" (DEFAULT: {default})".format(default=default)) pubsub_group.add_argument("-n", "--node", type=unicode_decoder, default=u'', help=node_help) if flags.single_item: @@ -359,6 +366,8 @@ if flags: raise exceptions.InternalError('unknowns flags: {flags}'.format(flags=u', '.join(flags))) + if defaults: + raise exceptions.InternalError('unused defaults: {defaults}'.format(defaults=defaults)) return parent @@ -759,7 +768,8 @@ self._use_pubsub = kwargs.pop('use_pubsub', False) if self._use_pubsub: flags = kwargs.pop('pubsub_flags', []) - parents.add(self.host.make_pubsub_group(flags)) + defaults = kwargs.pop('pubsub_defaults', {}) + parents.add(self.host.make_pubsub_group(flags, defaults)) self._pubsub_flags = flags # other common options