diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index 90b92787d..65d90fc79 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -32,6 +32,7 @@ def init_config_cli( optimize: Optimizations = Opt(Optimizations.efficiency.value, "--optimize", "-o", help="Whether to optimize for efficiency (faster inference, smaller model, lower memory consumption) or higher accuracy (potentially larger and slower model). This will impact the choice of architecture, pretrained weights and related hyperparameters."), gpu: bool = Opt(False, "--gpu", "-G", help="Whether the model can run on GPU. This will impact the choice of architecture, pretrained weights and related hyperparameters."), pretraining: bool = Opt(False, "--pretraining", "-pt", help="Include config for pretraining (with 'spacy pretrain')"), + force_overwrite: bool = Opt(False, "--force", "-F", help="Force overwriting the output file"), # fmt: on ): """ @@ -46,6 +47,12 @@ def init_config_cli( optimize = optimize.value pipeline = string_to_list(pipeline) is_stdout = str(output_file) == "-" + if not is_stdout and output_file.exists() and not force_overwrite: + msg = Printer() + msg.fail( + "The provided output file already exists. To force overwriting the config file, set the --force or -F flag.", + exits=1, + ) config = init_config( lang=lang, pipeline=pipeline, diff --git a/website/docs/api/cli.md b/website/docs/api/cli.md index 3fd6b7a76..6dc8de900 100644 --- a/website/docs/api/cli.md +++ b/website/docs/api/cli.md @@ -128,7 +128,7 @@ customize those settings in your config file later. > ``` ```cli -$ python -m spacy init config [output_file] [--lang] [--pipeline] [--optimize] [--gpu] [--pretraining] +$ python -m spacy init config [output_file] [--lang] [--pipeline] [--optimize] [--gpu] [--pretraining] [--force] ``` | Name | Description | @@ -139,6 +139,7 @@ $ python -m spacy init config [output_file] [--lang] [--pipeline] [--optimize] [ | `--optimize`, `-o` | `"efficiency"` or `"accuracy"`. Whether to optimize for efficiency (faster inference, smaller model, lower memory consumption) or higher accuracy (potentially larger and slower model). This will impact the choice of architecture, pretrained weights and related hyperparameters. Defaults to `"efficiency"`. ~~str (option)~~ | | `--gpu`, `-G` | Whether the model can run on GPU. This will impact the choice of architecture, pretrained weights and related hyperparameters. ~~bool (flag)~~ | | `--pretraining`, `-pt` | Include config for pretraining (with [`spacy pretrain`](/api/cli#pretrain)). Defaults to `False`. ~~bool (flag)~~ | +| `--force`, `-f` | Force overwriting the output file if it already exists. ~~bool (flag)~~ | | `--help`, `-h` | Show help message and available arguments. ~~bool (flag)~~ | | **CREATES** | The config file for training. |