summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2018-03-09 16:32:49 +0100
committerRobin Krahl <me@robin-krahl.de>2018-03-09 16:32:49 +0100
commit8d014787c2cce2b6f4afdaa344bb1763b239ffa5 (patch)
tree987cf08642fc3c955bb5f0576e90b8d7d0c35cf0
parentcfa1913e70ac5dc60939750e27c5ebf9637415d7 (diff)
downloadbibtool-8d014787c2cce2b6f4afdaa344bb1763b239ffa5.tar.gz
bibtool-8d014787c2cce2b6f4afdaa344bb1763b239ffa5.tar.bz2
Do not require a save when editing Bibtex data
By default, click.edit returns None if the user did not save. But in our case, just checking the data without saving is a realistic scenario that should be interpreted as a confirmation of the data.
-rw-r--r--bibtool/cli.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/bibtool/cli.py b/bibtool/cli.py
index 3056933..43d6c21 100644
--- a/bibtool/cli.py
+++ b/bibtool/cli.py
@@ -35,13 +35,16 @@ def _import(filename, directory, delete):
click.echo('Found one Bibtex entry: ' + entry['ID'])
if click.confirm('Do you want to edit the entry?'):
edited_data = click.edit(bibtexparser.dumps(bibtex_data),
- extension='.bib')
- if edited_data:
- bibtex_data = bibtexparser.loads(edited_data)
- if len(bibtex_data.entries) != 1:
- raise Exception('The edited data must contain exactly one'
- 'Bibtex entry.')
- entry = bibtex_data.entries[0]
+ extension='.bib', require_save=None)
+ if not edited_data:
+ click.echo('Empty Bibtex data. Aborting.')
+ return
+
+ bibtex_data = bibtexparser.loads(edited_data)
+ if len(bibtex_data.entries) != 1:
+ raise Exception('The edited data must contain exactly one '
+ 'Bibtex entry.')
+ entry = bibtex_data.entries[0]
click.confirm('Add {} to the repository?'.format(entry['ID']),
default=True, abort=True)