From f3d89e13a7d101d72ce3369fcb98188458175d4d Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sun, 13 Oct 2019 18:17:48 +0200 Subject: Added edit command to patterncfg --- patternutils/commands/patterncfg.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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) -- cgit v1.3.1