Better rename and error dialogue
info() messages now print on stdout. warning() and error() still print on stderr. Fix #50
This commit is contained in:
parent
b4d066e1f9
commit
e979aae85b
@ -105,7 +105,7 @@ def command(conf, args):
|
||||
if not path.endswith('/'):
|
||||
path += '/'
|
||||
else:
|
||||
ui.error('{} is not a directory. Quit.'.format(
|
||||
ui.error('{} is not a directory.'.format(
|
||||
color.dye_err(args.path[0], 'filepath')))
|
||||
ui.exit(1)
|
||||
|
||||
@ -130,7 +130,7 @@ def command(conf, args):
|
||||
paper = rp.pull_paper(citekey)
|
||||
|
||||
if paper.docpath is None:
|
||||
ui.error('No document associated with the entry {}. Quit.'.format(
|
||||
ui.error('No document associated with the entry {}.'.format(
|
||||
color.dye_err(citekey, 'citekey')))
|
||||
ui.exit()
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
from ..uis import get_ui
|
||||
from .. import color
|
||||
from .. import repo
|
||||
from ..utils import resolve_citekey
|
||||
|
||||
@ -24,3 +25,6 @@ def command(conf, args):
|
||||
key = resolve_citekey(repo=rp, citekey=args.citekey, ui=ui, exit_on_fail=True)
|
||||
paper = rp.pull_paper(key)
|
||||
rp.rename_paper(paper, args.new_citekey)
|
||||
ui.message("The '{}' citekey has been renamed into '{}'".format(
|
||||
color.dye_out(args.citekey, 'citekey'),
|
||||
color.dye_out(args.new_citekey, 'citekey')))
|
||||
|
@ -69,8 +69,8 @@ class PrintUI(object):
|
||||
print(*messages, **kwargs)
|
||||
|
||||
def info(self, message, **kwargs):
|
||||
kwargs['file'] = self._stderr
|
||||
print(u'{}: {}'.format(color.dye_err('info', 'ok'), message), **kwargs)
|
||||
kwargs['file'] = self._stdout
|
||||
print(u'{}: {}'.format(color.dye_out('info', 'ok'), message), **kwargs)
|
||||
|
||||
def warning(self, message, **kwargs):
|
||||
kwargs['file'] = self._stderr
|
||||
|
@ -16,12 +16,12 @@ 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("'{}' 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:
|
||||
citekeys = sorted(citekeys)
|
||||
ui.error("Be more specific; Provided citekey '{}' matches multiples citekeys:".format(
|
||||
ui.error("Be more specific; '{}' matches multiples citekeys:".format(
|
||||
citekey))
|
||||
for c in citekeys:
|
||||
p = repo.pull_paper(c)
|
||||
|
@ -363,6 +363,7 @@ class TestUsecase(DataCommandTestCase):
|
||||
'\n',
|
||||
'',
|
||||
'network search\n',
|
||||
'info: Assuming search to be a tag.\n'
|
||||
'[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) | network,search\n',
|
||||
]
|
||||
|
||||
@ -508,7 +509,7 @@ class TestUsecase(DataCommandTestCase):
|
||||
'pubs tag junk'
|
||||
]
|
||||
outs = self.execute_cmds(cmds)
|
||||
self.assertEqual(1, len(outs[2].splitlines()))
|
||||
self.assertEqual(2, len(outs[2].splitlines()))
|
||||
|
||||
def test_doc_open(self):
|
||||
cmds = ['pubs init',
|
||||
|
Loading…
x
Reference in New Issue
Block a user