diff options
Diffstat (limited to 'patternutils/commands/tmv.py')
| -rw-r--r-- | patternutils/commands/tmv.py | 11 |
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 = {} |
