# HG changeset patch # User Goffi # Date 1522514454 -7200 # Node ID 38e1e29c48e910321537130b0f840418d666e2f6 # Parent b27165bf160c2451e6b4c2b429245dbfbc512748 jp (base): added C.ITEM pubsub flag when --item is required diff -r b27165bf160c -r 38e1e29c48e9 frontends/src/jp/base.py --- a/frontends/src/jp/base.py Sat Mar 31 18:23:06 2018 +0200 +++ b/frontends/src/jp/base.py Sat Mar 31 18:40:54 2018 +0200 @@ -355,7 +355,12 @@ pubsub_group.add_argument("-n", "--node", type=unicode_decoder, default=u'', help=node_help) if flags.single_item: - pubsub_group.add_argument("-i", "--item", type=unicode_decoder, help=_(u"item to retrieve")) + item_help = (u"item to retrieve") + if not flags.item: + default = defaults.pop(u'item', _(u'last item')) + if default is not None: + item_help += _(u" (DEFAULT: {default})".format(default=default)) + pubsub_group.add_argument("-i", "--item", type=unicode_decoder, help=item_help) pubsub_group.add_argument("-L", "--last-item", action='store_true', help=_(u'retrieve last item')) elif flags.multi_items: # mutiple items @@ -516,6 +521,8 @@ self.parser.error(_(u"argument -s/--service is required")) if C.NODE in flags and not self.args.node: self.parser.error(_(u"argument -n/--node is required")) + if C.ITEM in flags and not self.args.item: + self.parser.error(_(u"argument -i/--item is required")) # FIXME: mutually groups can't be nested in a group and don't support title # so we check conflict here. This may be fixed in Python 3, to be checked diff -r b27165bf160c -r 38e1e29c48e9 frontends/src/jp/constants.py --- a/frontends/src/jp/constants.py Sat Mar 31 18:23:06 2018 +0200 +++ b/frontends/src/jp/constants.py Sat Mar 31 18:40:54 2018 +0200 @@ -39,6 +39,7 @@ # Pubsub options flags SERVICE = u'service' # service required NODE = u'node' # node required + ITEM = u'item' # item required SINGLE_ITEM = u'single_item' # only one item is allowed MULTI_ITEMS = u'multi_items' # multiple items are allowed NO_MAX = u'no_max' # don't add --max option for multi items