Skip to content

Commit cc61295

Browse files
committed
Added --force option
1 parent c803002 commit cc61295

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

translate-messages/.translate-msgs.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"keys": "",
55
"exclude_langs": "",
66
"exclude_keys": "",
7+
"force": false,
78
"no_wizard": false
89
}

translate-messages/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Options can be set by using command-line arguments:
4747
| `-k`, `--keys` | Comma-separated list of keys to translate | `--keys=appDesc,err_notFound`
4848
| `--exclude-keys` | Comma-separated list of keys to ignore | `--exclude-keys=appName,author`
4949
| `-i`, `--init` | Create .translate-msgs.config.json in project root to store defaults |
50+
| `-f`, `--force` | Force overwrite of existing config file when using `--init` |
5051
| `-W`, `--no-wizard` | Skip interactive prompts during start-up |
5152
| `-h`, `--help` | Show help screen |
5253

translate-messages/src/translate_messages/lib/init.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def cli(caller_file):
3535
argp.add_argument('--exclude-langs', '--exclude-lang', type=str, help='Languages to exclude (e.g. "en,es")')
3636
argp.add_argument('--exclude-keys', '--ignore-keys', type=str, help='Keys to ignore (e.g. "appName,author")')
3737
argp.add_argument('-i', '--init', action='store_true', help=f'Create {cli.name}.config.json file to store defaults')
38+
argp.add_argument('-f', '--force', action='store_true', help='Force overwrite existing config file when using --init')
3839
argp.add_argument('-W', '--no-wizard', '--skip-wizard',
3940
action='store_true', default=None, help='Skip interactive prompts during start-up')
4041
argp.add_argument('-h', '--help', action='help', help="Show help screen")
@@ -49,12 +50,19 @@ def cli(caller_file):
4950
cli.config.locales_dir = getattr(cli.config, 'locales_dir', '_locales')
5051
if cli.config.exclude_langs:
5152
cli.config.target_locales = [lang for lang in cli.config.target_locales if lang not in cli.config.exclude_langs]
53+
cli.config.force = getattr(cli.config, 'force', False)
5254
cli.config.no_wizard = getattr(cli.config, 'no_wizard', False)
5355

5456
return cli
5557

5658
def config_file(cli):
57-
if os.path.exists(cli.config_path) : return print(f'Config already exists at {cli.config_path}')
59+
if os.path.exists(cli.config_path):
60+
if cli.config.force:
61+
print(f'Overwriting existing config at {cli.config_path}...')
62+
else:
63+
print(f'Config already exists at {cli.config_path}.Skipping --init.')
64+
print('\nTIP: Pass --force to overwrite.')
65+
return
5866
cli.config_filename = '.translate-msgs.config.json'
5967
cli.config_path = os.path.join(cli.project_root, cli.config_filename)
6068
try:

0 commit comments

Comments
 (0)