jp (common): added --last-item to take last item when no item id is found/given
This commit is contained in:
parent
7f13ed15fd
commit
be2bb0ff3f
2 changed files with 10 additions and 3 deletions
|
|
@ -300,7 +300,7 @@ class Get(base.CommandBase):
|
||||||
class Edit(base.CommandBase, common.BaseEdit):
|
class Edit(base.CommandBase, common.BaseEdit):
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
base.CommandBase.__init__(self, host, 'edit', use_verbose=True, use_pubsub_node_req=True, help=_(u'edit an existing or new pubsub item'))
|
base.CommandBase.__init__(self, host, 'edit', use_verbose=True, use_pubsub=True, help=_(u'edit an existing or new pubsub item'))
|
||||||
common.BaseEdit.__init__(self, self.host, PUBSUB_TMP_DIR)
|
common.BaseEdit.__init__(self, self.host, PUBSUB_TMP_DIR)
|
||||||
|
|
||||||
def add_parser_options(self):
|
def add_parser_options(self):
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,9 @@ class BaseEdit(object):
|
||||||
self.use_metadata = use_metadata
|
self.use_metadata = use_metadata
|
||||||
|
|
||||||
def add_parser_options(self):
|
def add_parser_options(self):
|
||||||
self.parser.add_argument("--force-item", action='store_true', help=_(u"don't use magic and take item argument as an actual item"))
|
group = self.parser.add_mutually_exclusive_group()
|
||||||
|
group.add_argument("--force-item", action='store_true', help=_(u"don't use magic and take item argument as an actual item"))
|
||||||
|
group.add_argument("--last-item", action='store_true', help=_(u"take last item instead of creating a new one if no item id is found"))
|
||||||
|
|
||||||
def secureUnlink(self, path):
|
def secureUnlink(self, path):
|
||||||
"""Unlink given path after keeping it for a while
|
"""Unlink given path after keeping it for a while
|
||||||
|
|
@ -375,11 +377,16 @@ class BaseEdit(object):
|
||||||
self.disp(u'No node found in xmpp: URI, can\'t retrieve item', error=True)
|
self.disp(u'No node found in xmpp: URI, can\'t retrieve item', error=True)
|
||||||
self.host.quit(1)
|
self.host.quit(1)
|
||||||
pubsub_item = pubsub_data.get('item',[None])[0]
|
pubsub_item = pubsub_data.get('item',[None])[0]
|
||||||
if pubsub_item is not None:
|
if pubsub_item is None and self.args.last_item:
|
||||||
|
command = 'last'
|
||||||
|
elif pubsub_item is not None:
|
||||||
command = 'edit' # XXX: edit command is only used internaly, it similar to last, but with the item given in the URL
|
command = 'edit' # XXX: edit command is only used internaly, it similar to last, but with the item given in the URL
|
||||||
else:
|
else:
|
||||||
command = 'new'
|
command = 'new'
|
||||||
|
|
||||||
|
if self.args.last_item and command != 'last':
|
||||||
|
self.parser.error(_(u"--last-item can't be used with a specified item"))
|
||||||
|
|
||||||
if not force_item and command in ('new', 'last', 'edit'):
|
if not force_item and command in ('new', 'last', 'edit'):
|
||||||
# we need a temporary file
|
# we need a temporary file
|
||||||
tmp_suff = '.' + self.getTmpSuff()
|
tmp_suff = '.' + self.getTmpSuff()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue