From 8d014787c2cce2b6f4afdaa344bb1763b239ffa5 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Fri, 9 Mar 2018 16:32:49 +0100 Subject: 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. --- bibtool/cli.py | 17 ++++++++++------- 1 file 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) -- cgit v1.2.1