tag cmd
This commit is contained in:
parent
c6d7300ae3
commit
24df1b36ae
@ -4,9 +4,9 @@ import list_cmd
|
||||
import open_cmd
|
||||
import websearch_cmd
|
||||
import remove_cmd
|
||||
import tag_cmd
|
||||
# import import_cmd
|
||||
# import export_cmd
|
||||
# import edit_cmd
|
||||
# import tag_cmd
|
||||
# import attach_cmd
|
||||
# import update_cmd
|
||||
|
@ -18,17 +18,16 @@ The different use cases are :
|
||||
"""
|
||||
|
||||
from ..repo import Repository, InvalidReference
|
||||
from . import helpers
|
||||
from ..configs import config
|
||||
from ..uis import get_ui
|
||||
from .. import pretty
|
||||
|
||||
def parser(subparsers):
|
||||
parser = subparsers.add_parser('tag', help="add, remove and show tags")
|
||||
parser.add_argument('referenceOrTag', nargs='?', default = None,
|
||||
help='reference to the paper (citekey or number), or '
|
||||
'tag.')
|
||||
parser.add_argument('citekeyOrTag', nargs='?', default = None,
|
||||
help='citekey or tag.')
|
||||
parser.add_argument('tags', nargs='?', default = None,
|
||||
help='If the previous argument was a reference, then '
|
||||
help='If the previous argument was a citekey, then '
|
||||
'then a list of tags separated by a +.')
|
||||
# TODO find a way to display clear help for multiple command semantics,
|
||||
# indistinguisable for argparse. (fabien, 201306)
|
||||
@ -69,19 +68,18 @@ def command(args):
|
||||
"""Add, remove and show tags"""
|
||||
|
||||
ui = get_ui()
|
||||
referenceOrTag = args.referenceOrTag
|
||||
citekeyOrTag = args.citekeyOrTag
|
||||
tags = args.tags
|
||||
|
||||
|
||||
rp = Repository(config())
|
||||
|
||||
if referenceOrTag is None:
|
||||
if citekeyOrTag is None:
|
||||
for tag in rp.get_tags():
|
||||
ui.print_(tag)
|
||||
else:
|
||||
try:
|
||||
citekey = rp.ref2citekey(referenceOrTag)
|
||||
p = rp.get_paper(citekey)
|
||||
if rp.databroker.exists(citekeyOrTag):
|
||||
p = rp.pull_paper(citekeyOrTag)
|
||||
if tags is None:
|
||||
ui.print_(' '.join(p.tags))
|
||||
else:
|
||||
@ -90,15 +88,15 @@ def command(args):
|
||||
p.add_tag(tag)
|
||||
for tag in remove_tags:
|
||||
p.remove_tag(tag)
|
||||
rp.save_paper(p)
|
||||
except InvalidReference:
|
||||
# case where we want to find paper with specific tags
|
||||
included, excluded = _tag_groups(_parse_tags(referenceOrTag))
|
||||
rp.push_paper(p, overwrite=True)
|
||||
else:
|
||||
# case where we want to find papers with specific tags
|
||||
included, excluded = _tag_groups(_parse_tags(citekeyOrTag))
|
||||
papers_list = []
|
||||
for n, p in enumerate(rp.all_papers()):
|
||||
if (p.tags.issuperset(included) and
|
||||
len(p.tags.intersection(excluded)) == 0):
|
||||
papers_list.append((p, n))
|
||||
|
||||
ui.print_('\n'.join(helpers.paper_oneliner(p, n)
|
||||
ui.print_('\n'.join(pretty.paper_oneliner(p, n)
|
||||
for p, n in papers_list))
|
||||
|
@ -44,7 +44,6 @@ def command(args):
|
||||
|
||||
if repo_version == 2:
|
||||
# update config
|
||||
print 'bla'
|
||||
cfg_update = [('papers-directory', 'papers_dir'),
|
||||
('open-cmd', 'open_cmd'),
|
||||
('edit-cmd', 'edit_cmd'),
|
||||
|
@ -19,10 +19,10 @@ CORE_CMDS = collections.OrderedDict([
|
||||
('open', commands.open_cmd),
|
||||
('websearch', commands.websearch_cmd),
|
||||
('remove', commands.remove_cmd),
|
||||
('tag', commands.tag_cmd),
|
||||
# ('import', commands.import_cmd),
|
||||
# ('export', commands.export_cmd),
|
||||
# ('edit', commands.edit_cmd),
|
||||
# ('tag', commands.tag_cmd),
|
||||
# ('attach', commands.attach_cmd),
|
||||
# ('update', commands.update_cmd),
|
||||
])
|
||||
|
Loading…
x
Reference in New Issue
Block a user