summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2019-10-13 18:17:48 +0200
committerDennis Fink2019-10-13 18:17:48 +0200
commitf3d89e13a7d101d72ce3369fcb98188458175d4d (patch)
treec6cb2702d99be6685f544264f026af57ab958837
parentabbfef44915a37186f7864aa111df4ee8f62a855 (diff)
downloadpatternutils-f3d89e13a7d101d72ce3369fcb98188458175d4d.tar.gz
patternutils-f3d89e13a7d101d72ce3369fcb98188458175d4d.zip
Added edit command to patterncfg
Diffstat (limited to '')
-rw-r--r--patternutils/commands/patterncfg.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/patternutils/commands/patterncfg.py b/patternutils/commands/patterncfg.py
index 3806b51..96e9ac7 100644
--- a/patternutils/commands/patterncfg.py
+++ b/patternutils/commands/patterncfg.py
@@ -117,3 +117,24 @@ def view(name: str, command: str, color: bool) -> None:
lexer = Python3Lexer
text = highlight(text, lexer(), TerminalFormatter())
click.echo(text[:-1])
+
+
+@patterncfg.command(name='edit', help='edit a template file')
+@click.option('-c', '--command', default=None, type=click.Choice(CURRENT_SUPPORTED_PROGRAMS),
+ help='select the command from which to edit the file')
+@click.argument('name')
+def edit(name: str, command: str) -> None:
+
+ files = config.find_templates(name, command)
+ 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:
+ filename = files[0]
+
+ click.edit(filename=filename)