Mercurial > libervia-backend
changeset 2547:2d69a0afe039
jp: new argument pubsub_default can be used in Commands to replace default value in help string
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 31 Mar 2018 17:10:43 +0200 (2018-03-31) |
parents | 48820e4a1f8a |
children | 54b3853b55c0 |
files | frontends/src/jp/base.py |
diffstat | 1 files changed, 14 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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