changeset 2552:38e1e29c48e9

jp (base): added C.ITEM pubsub flag when --item is required
author Goffi <goffi@goffi.org>
date Sat, 31 Mar 2018 18:40:54 +0200
parents b27165bf160c
children 39b10475f56b
files frontends/src/jp/base.py frontends/src/jp/constants.py
diffstat 2 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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