From 4962fa114e4faea41972d48a969599edb70cc8e6 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Wed, 28 Aug 2019 20:10:37 +0200 Subject: Check for amount of files in patterncfg remove --- patternutils/commands/patterncfg.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/patternutils/commands/patterncfg.py b/patternutils/commands/patterncfg.py index 434387d..aace2ba 100644 --- a/patternutils/commands/patterncfg.py +++ b/patternutils/commands/patterncfg.py @@ -54,11 +54,17 @@ def add(file_type: str, command: Optional[str], name: str) -> None: def remove(command: Optional[str], name: str) -> None: files = config.find_templates(name, command) - try: - os.remove(files[0]) - except IndexError: - click.secho('Cannot remove {}. It doesn\'t exist!'.format(name), fg='red', err=True) + + if not files: + click.secho('No files found!', fg='red', err=True) + raise SystemExit + elif len(files) != 1: + click.secho('Multiple files found!', fg='red', err=True) + for f in files: + click.secho(f, fg='red', err=True) raise SystemExit + else: + os.remove(files[0]) @patterncfg.command(name='view', help='view template file') -- cgit v1.3.1