summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2019-08-28 20:10:37 +0200
committerDennis Fink2019-08-28 20:10:37 +0200
commit4962fa114e4faea41972d48a969599edb70cc8e6 (patch)
tree36aadbe97554533dd5ffcc13e53fe0aa9ebf0ce9
parentebd45b7aaa977ec45963698561c4633f48a6960c (diff)
downloadpatternutils-4962fa114e4faea41972d48a969599edb70cc8e6.tar.gz
patternutils-4962fa114e4faea41972d48a969599edb70cc8e6.zip
Check for amount of files in patterncfg remove
Diffstat (limited to '')
-rw-r--r--patternutils/commands/patterncfg.py14
1 files 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')