summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2019-08-19 20:09:24 +0200
committerDennis Fink2019-08-19 20:09:24 +0200
commit046465ab68796a7a89f68ef96da1cbfedc33060d (patch)
tree2cb385840c9cbfff46510d66e2dcb8d8b120273c
parentce92d7412ef51481a03b5ec64d043dcb0a799867 (diff)
downloadpatternutils-046465ab68796a7a89f68ef96da1cbfedc33060d.tar.gz
patternutils-046465ab68796a7a89f68ef96da1cbfedc33060d.zip
Added key option to tmv
-rw-r--r--patternutils/commands/tmv.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py
index 7d0be21..8147c11 100644
--- a/patternutils/commands/tmv.py
+++ b/patternutils/commands/tmv.py
@@ -24,6 +24,8 @@ def move_file(old_filename: str, new_filename: str) -> None:
help='force rename')
@click.option('-t', '--template-engine', default='python', type=click.Choice(['python', 'jinja2']),
help='select the template engine to use')
+@click.option('-k', '--key', default='_abspath',
+ help='select the key to use as the source file')
@click.option('-p', '--use-predefined-template', is_flag=True, default=False,
help='use predefined template')
@click.option('--read-from', default='-', type=click.File('r'))
@@ -43,6 +45,7 @@ def tmv(
abort_on_path_exist: bool,
use_predefined_template: bool,
read_from: click.File,
+ key: str,
dry_run: bool,
verbose: bool,
) -> None:
@@ -50,9 +53,9 @@ def tmv(
"""Rename files based on the OUTPUT_PATTERN.
It read a JSON list containing objects. The object needs to have a
- key named _abspath, which points to the file to move. The rest of the
- keys will be supplied to the templating engine to generate the new
- filename.
+ key named as the option KEY (default: _abspath), which points to
+ the file to move. The rest of the keys will be supplied to the
+ templating engine to generate the new filename.
"""
try:
@@ -77,7 +80,7 @@ def tmv(
click.secho('jinja2 not installed!', fg='red', err=True)
raise SystemExit
- new_filenames = dict((entry['_abspath'], render(**entry)) for entry in data)
+ new_filenames = dict((entry[key], render(**entry)) for entry in data)
has_existing = False
non_existing = {}