jp (base, pubsub, ticket): handle order-by:
--order-by has been added to pubsub group. New getPubsubExtra helper method generate extra dict according to arguments. getPubsubExtra is used for pubsub/get, blog/get and and ticket/get.
This commit is contained in:
parent
3e63d54e3d
commit
169165e4ee
4 changed files with 33 additions and 4 deletions
|
|
@ -375,6 +375,14 @@ class Jp(object):
|
|||
if not flags.no_max:
|
||||
pubsub_group.add_argument("-m", "--max-items", dest="max", type=int, default=10,
|
||||
help=_(u"maximum number of items to get ({no_limit} to get all items)".format(no_limit=C.NO_LIMIT)))
|
||||
# TODO: order-by should be a list to handle several levels of ordering
|
||||
# but this is not yet done in SàT (and not really useful with
|
||||
# current specifications, as only "creation" and "modification" are
|
||||
# available)
|
||||
pubsub_group.add_argument(
|
||||
"-o", "--order-by", choices=[C.ORDER_BY_CREATION,
|
||||
C.ORDER_BY_MODIFICATION],
|
||||
help=_(u"how items should be ordered"))
|
||||
|
||||
if not flags.all_used:
|
||||
raise exceptions.InternalError('unknown flags: {flags}'.format(flags=u', '.join(flags.unused)))
|
||||
|
|
@ -979,6 +987,27 @@ class CommandBase(object):
|
|||
self.disp(msg.format(failure_), error=True)
|
||||
self.host.quit(exit_code)
|
||||
|
||||
def getPubsubExtra(self, extra=None):
|
||||
"""Helper method to compute extra data from pubsub arguments
|
||||
|
||||
@param extra(None, dict): base extra dict, or None to generate a new one
|
||||
@return (dict): dict which can be used directly in the bridge for pubsub
|
||||
"""
|
||||
if extra is None:
|
||||
extra = {}
|
||||
else:
|
||||
if {C.KEY_ORDER_BY}.intersection(extra.keys()):
|
||||
raise exceptions.InternalError(
|
||||
u"given extra dict has conflicting keys with pubsub keys")
|
||||
try:
|
||||
order_by = self.args.order_by
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
if order_by is not None:
|
||||
extra[C.KEY_ORDER_BY] = self.args.order_by
|
||||
return extra
|
||||
|
||||
def add_parser_options(self):
|
||||
try:
|
||||
subcommands = self.subcommands
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ class Get(base.CommandBase):
|
|||
self.args.node,
|
||||
self.args.max,
|
||||
self.args.items,
|
||||
{},
|
||||
self.getPubsubExtra(),
|
||||
self.profile,
|
||||
callback=self.mbGetCb,
|
||||
errback=self.mbGetEb,
|
||||
|
|
|
|||
|
|
@ -760,7 +760,7 @@ class Get(base.CommandBase):
|
|||
self.args.max,
|
||||
self.args.items,
|
||||
self.args.sub_id,
|
||||
{},
|
||||
self.getPubsubExtra(),
|
||||
self.profile,
|
||||
callback=self.psItemsGetCb,
|
||||
errback=self.psItemsGetEb,
|
||||
|
|
@ -1217,7 +1217,7 @@ class Search(base.CommandBase):
|
|||
self.args.max,
|
||||
items,
|
||||
"",
|
||||
{},
|
||||
self.getPubsubExtra(),
|
||||
self.profile,
|
||||
callback=search,
|
||||
errback=errback,
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class Get(base.CommandBase):
|
|||
self.args.max,
|
||||
self.args.items,
|
||||
u"",
|
||||
{},
|
||||
self.getPubsubExtra(),
|
||||
self.profile,
|
||||
callback=self.ticketsGetCb,
|
||||
errback=partial(
|
||||
|
|
|
|||
Loading…
Reference in a new issue