jp (base): fixed default values for --max-items and --max when using pubsub
This commit is contained in:
parent
9ad46b42f2
commit
0dad996942
1 changed files with 31 additions and 8 deletions
|
|
@ -374,19 +374,21 @@ class Jp(object):
|
|||
# and Orbder-by
|
||||
pubsub_group.add_argument("-i", "--item", type=unicode_decoder, action='append', dest='items', default=[], help=_(u"items to retrieve (DEFAULT: all)"))
|
||||
if not flags.no_max:
|
||||
pubsub_group.add_argument(
|
||||
"-M", "--max-items", dest="max", type=int, default=10,
|
||||
max_group = pubsub_group.add_mutually_exclusive_group()
|
||||
# XXX: defaut value for --max-items or --max is set in parse_pubsub_args
|
||||
max_group.add_argument(
|
||||
"-M", "--max-items", dest="max", type=int,
|
||||
help=_(u"maximum number of items to get ({no_limit} to get all items)"
|
||||
.format(no_limit=C.NO_LIMIT)))
|
||||
# FIXME: it could be possible to no duplicate max (between pubsub
|
||||
# max-items and RSM max)should not be duplicated, RSM could be
|
||||
# used when available and pubsub max otherwise
|
||||
max_group.add_argument(
|
||||
"-m", "--max", dest="rsm_max", type=int,
|
||||
help=_(u"maximum number of items to get per page (DEFAULT: 10)"))
|
||||
|
||||
# RSM
|
||||
|
||||
# FIXME: it could be possible to no duplicate max (between pubsub max-items
|
||||
# and RSM max)should not be duplicated, RSM could be used when
|
||||
# available and pubsub max otherwise
|
||||
pubsub_group.add_argument(
|
||||
"-m", "--max", dest="rsm_max", type=int, default=10,
|
||||
help=_(u"maximum number of items to get per page (DEFAULT: 10)"))
|
||||
rsm_page_group = pubsub_group.add_mutually_exclusive_group()
|
||||
rsm_page_group.add_argument(
|
||||
"-a", "--after", dest="rsm_after", type=unicode_decoder,
|
||||
|
|
@ -594,6 +596,27 @@ class Jp(object):
|
|||
except AttributeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
max_items = self.args.max
|
||||
rsm_max = self.args.rsm_max
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
# we need to set a default value for max, but we need to know if we want
|
||||
# to use pubsub's max or RSM's max. The later is used if any RSM or MAM
|
||||
# argument is set
|
||||
if max_items is None and rsm_max is None:
|
||||
to_check = ('mam_filters', 'rsm_max', 'rsm_after', 'rsm_before',
|
||||
'rsm_index')
|
||||
if any((getattr(self.args, name) for name in to_check)):
|
||||
# we use RSM
|
||||
self.args.rsm_max = 10
|
||||
else:
|
||||
# we use pubsub without RSM
|
||||
self.args.max = 10
|
||||
if self.args.max is None:
|
||||
self.args.max = C.NO_LIMIT
|
||||
|
||||
def run(self, args=None, namespace=None):
|
||||
self.args = self.parser.parse_args(args, namespace=None)
|
||||
if self.args._cmd._use_pubsub:
|
||||
|
|
|
|||
Loading…
Reference in a new issue