jp: new argument pubsub_default can be used in Commands to replace default value in help string
This commit is contained in:
parent
ec0c5104ed
commit
31c8a752bb
1 changed files with 14 additions and 4 deletions
|
|
@ -324,10 +324,13 @@ class Jp(object):
|
|||
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 @@ class Jp(object):
|
|||
|
||||
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 @@ class Jp(object):
|
|||
|
||||
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 @@ class CommandBase(object):
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue