All commands that consume a citekey as an argument will now complete a
prefix.
This commit is contained in:
parent
69b2879fa2
commit
5cc3f892a0
@ -22,8 +22,8 @@ def command(conf, args):
|
||||
config.check_conf(new_conf)
|
||||
ui.message('The configuration file was updated.')
|
||||
break
|
||||
except AssertionError: # TODO better error message
|
||||
ui.error('Error reading the modified configuration file.')
|
||||
except AssertionError as e: # TODO better error message
|
||||
ui.error('Error reading the modified configuration file [' + e.message + '].')
|
||||
options = ['edit_again', 'abort']
|
||||
choice = options[ui.input_choice(
|
||||
options, ['e', 'a'],
|
||||
|
@ -115,7 +115,7 @@ def command(conf, args):
|
||||
if not path.endswith('/'):
|
||||
path += '/'
|
||||
else:
|
||||
ui.error('{} is not a directory.'.format(
|
||||
ui.error('{} is not a directory. Quit.'.format(
|
||||
color.dye_err(args.path[0], 'filepath')))
|
||||
ui.exit(1)
|
||||
|
||||
@ -140,7 +140,7 @@ def command(conf, args):
|
||||
paper = rp.pull_paper(citekey)
|
||||
|
||||
if paper.docpath is None:
|
||||
ui.error('No document associated with the entry {}.'.format(
|
||||
ui.error('No document associated with the entry {}. Quit.'.format(
|
||||
color.dye_err(citekey, 'citekey')))
|
||||
ui.exit()
|
||||
|
||||
|
@ -3,7 +3,7 @@ from __future__ import print_function
|
||||
from .. import repo
|
||||
from ..uis import get_ui
|
||||
from .. import endecoder
|
||||
|
||||
from ..utils import resolve_citekey_list
|
||||
|
||||
def parser(subparsers):
|
||||
parser = subparsers.add_parser('export', help='export bibliography')
|
||||
@ -19,20 +19,20 @@ def command(conf, args):
|
||||
# :param bib_format (only 'bibtex' now)
|
||||
|
||||
ui = get_ui()
|
||||
|
||||
rp = repo.Repository(conf)
|
||||
|
||||
try:
|
||||
papers = [rp.pull_paper(c) for c in args.citekeys]
|
||||
except repo.InvalidReference as v:
|
||||
ui.error(v)
|
||||
ui.exit(1)
|
||||
|
||||
if len(papers) == 0:
|
||||
papers = []
|
||||
if len(args.citekeys) < 1:
|
||||
papers = rp.all_papers()
|
||||
else:
|
||||
for key in resolve_citekey_list(repo=rp, citekeys=args.citekeys, ui=ui, exit_on_fail=True):
|
||||
papers.append(rp.pull_paper(key))
|
||||
bib = {}
|
||||
for p in papers:
|
||||
bib[p.citekey] = p.bibdata
|
||||
exporter = endecoder.EnDecoder()
|
||||
bibdata_raw = exporter.encode_bibdata(bib)
|
||||
ui.message(bibdata_raw)
|
||||
except Exception as e:
|
||||
ui.error(e.message)
|
@ -77,17 +77,17 @@ def command(conf, args):
|
||||
try:
|
||||
p = papers[k]
|
||||
if isinstance(p, Exception):
|
||||
ui.error('could not load entry for citekey {}.'.format(k))
|
||||
ui.error('Could not load entry for citekey {}.'.format(k))
|
||||
else:
|
||||
rp.push_paper(p)
|
||||
ui.message('{} imported'.format(color.dye_out(p.citekey, 'citekey')))
|
||||
ui.info('{} imported.'.format(color.dye_out(p.citekey, 'citekey')))
|
||||
docfile = bibstruct.extract_docfile(p.bibdata)
|
||||
if docfile is None:
|
||||
ui.warning("no file for {}.".format(p.citekey))
|
||||
ui.warning("No file for {}.".format(p.citekey))
|
||||
else:
|
||||
rp.push_doc(p.citekey, docfile, copy=copy)
|
||||
#FIXME should move the file if configured to do so.
|
||||
except KeyError:
|
||||
ui.error('no entry found for citekey {}.'.format(k))
|
||||
ui.error('No entry found for citekey {}.'.format(k))
|
||||
except IOError as e:
|
||||
ui.error(e.message)
|
||||
|
@ -33,7 +33,7 @@ def command(conf, args):
|
||||
pubsdir = system_path(pubsdir)
|
||||
|
||||
if check_directory(pubsdir, fail=False) and len(os.listdir(pubsdir)) > 0:
|
||||
ui.error('directory {} is not empty.'.format(
|
||||
ui.error('Directory {} is not empty.'.format(
|
||||
color.dye_err(pubsdir, 'filepath')))
|
||||
ui.exit()
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
from .. import repo
|
||||
from .. import content
|
||||
from ..uis import get_ui
|
||||
from ..utils import resolve_citekey
|
||||
|
||||
|
||||
def parser(subparsers):
|
||||
@ -16,11 +17,10 @@ def command(conf, args):
|
||||
"""
|
||||
|
||||
ui = get_ui()
|
||||
|
||||
rp = repo.Repository(conf)
|
||||
if not rp.databroker.exists(args.citekey):
|
||||
ui.error("citekey {} not found".format(args.citekey))
|
||||
ui.exit(1)
|
||||
|
||||
notepath = rp.databroker.real_notepath(args.citekey)
|
||||
citekey = resolve_citekey(rp, args.citekey, ui=ui, exit_on_fail=True)
|
||||
try:
|
||||
notepath = rp.databroker.real_notepath(citekey)
|
||||
content.edit_file(conf['main']['edit_cmd'], notepath, temporary=False)
|
||||
except Exception as e:
|
||||
ui.error(e.message)
|
@ -23,6 +23,7 @@ from ..repo import Repository
|
||||
from ..uis import get_ui
|
||||
from .. import pretty
|
||||
from .. import color
|
||||
from ..utils import resolve_citekey
|
||||
|
||||
|
||||
def parser(subparsers):
|
||||
@ -81,7 +82,12 @@ def command(conf, args):
|
||||
if citekeyOrTag is None:
|
||||
ui.message(color.dye_out(' '.join(sorted(rp.get_tags())), 'tag'))
|
||||
else:
|
||||
if rp.databroker.exists(citekeyOrTag):
|
||||
not_citekey = False
|
||||
try:
|
||||
citekeyOrTag = resolve_citekey(repo=rp, citekey=citekeyOrTag, ui=ui, exit_on_fail=True)
|
||||
except SystemExit:
|
||||
not_citekey = True
|
||||
if not not_citekey:
|
||||
p = rp.pull_paper(citekeyOrTag)
|
||||
if tags is None:
|
||||
ui.message(color.dye_out(' '.join(sorted(p.tags)), 'tag'))
|
||||
@ -93,9 +99,10 @@ def command(conf, args):
|
||||
p.remove_tag(tag)
|
||||
rp.push_paper(p, overwrite=True)
|
||||
elif tags is not None:
|
||||
ui.error(ui.error('no entry found for citekey {}.'.format(citekeyOrTag)))
|
||||
ui.error(ui.error('No entry found for citekey {}.'.format(citekeyOrTag)))
|
||||
ui.exit()
|
||||
else:
|
||||
ui.info('Assuming {} to be a tag.'.format(color.dye_out(citekeyOrTag)))
|
||||
# case where we want to find papers with specific tags
|
||||
included, excluded = _tag_groups(_parse_tag_seq(citekeyOrTag))
|
||||
papers_list = []
|
||||
|
@ -112,7 +112,7 @@ class InputUI(PrintUI):
|
||||
option_str = '/'.join(["{}{}".format(color.dye_out(c, 'bold'), s[1:])
|
||||
for c, s in zip(displayed_chars, options)])
|
||||
|
||||
self.message('{} {}: '.format(question, option_str), end='')
|
||||
self.message('{}: {} {}: '.format(color.dye_err('prompt', 'warning'), question, option_str), end='')
|
||||
while True:
|
||||
answer = self.input()
|
||||
if answer is None or answer == '':
|
||||
|
@ -5,6 +5,7 @@ from . import pretty
|
||||
|
||||
def resolve_citekey(repo, citekey, ui=None, exit_on_fail=True):
|
||||
"""Check that a citekey exists, or autocompletes it if not ambiguous."""
|
||||
""" :returns found citekey """
|
||||
# FIXME. Make me optionally non ui interactive/exiting
|
||||
citekeys = repo.citekeys_from_prefix(citekey)
|
||||
if len(citekeys) == 0:
|
||||
@ -15,7 +16,7 @@ def resolve_citekey(repo, citekey, ui=None, exit_on_fail=True):
|
||||
elif len(citekeys) == 1:
|
||||
if citekeys[0] != citekey:
|
||||
if ui is not None:
|
||||
ui.info("Provided citekey '{}' has been autocompleted into '{}'".format(color.dye_out(citekey, 'citekey'), color.dye_out(citekeys[0], 'citekey')))
|
||||
ui.info("Provided citekey '{}' has been autocompleted into [{}].".format(color.dye_out(citekey, 'citekey'), color.dye_out(citekeys[0], 'citekey')))
|
||||
citekey = citekeys[0]
|
||||
elif citekey not in citekeys:
|
||||
if ui is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user