diff options
| -rw-r--r-- | patternutils/commands/patterncfg.py | 21 |
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) |
