diff options
author | Robin Krahl <me@robin-krahl.de> | 2018-03-09 16:32:49 +0100 |
---|---|---|
committer | Robin Krahl <me@robin-krahl.de> | 2018-03-09 16:32:49 +0100 |
commit | 8d014787c2cce2b6f4afdaa344bb1763b239ffa5 (patch) | |
tree | 987cf08642fc3c955bb5f0576e90b8d7d0c35cf0 | |
parent | cfa1913e70ac5dc60939750e27c5ebf9637415d7 (diff) | |
download | bibtool-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.py | 17 |
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) |