diff --git a/spacy/cli/_util.py b/spacy/cli/_util.py index 064d368d7..f277988f8 100644 --- a/spacy/cli/_util.py +++ b/spacy/cli/_util.py @@ -68,10 +68,13 @@ def parse_config_overrides(args: List[str]) -> Dict[str, Any]: opt = opt.replace("--", "").replace("-", "_") if "." not in opt: msg.fail(f"{err}: can't override top-level section", exits=1) - if not args or args[0].startswith("--"): # flag with no value - value = "true" + if "=" in opt: # we have --opt=value + opt, value = opt.split("=", 1) else: - value = args.pop(0) + if not args or args[0].startswith("--"): # flag with no value + value = "true" + else: + value = args.pop(0) # Just like we do in the config, we're calling json.loads on the # values. But since they come from the CLI, it'd be unintuitive to # explicitly mark strings with escaped quotes. So we're working diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 4db5e8f44..b5cc6fff8 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -298,9 +298,13 @@ def test_project_config_validation2(config, n_errors): [ # fmt: off (["--x.foo", "10"], {"x.foo": 10}), + (["--x.foo=10"], {"x.foo": 10}), (["--x.foo", "bar"], {"x.foo": "bar"}), + (["--x.foo=bar"], {"x.foo": "bar"}), (["--x.foo", "--x.bar", "baz"], {"x.foo": True, "x.bar": "baz"}), - (["--x.foo", "10.1", "--x.bar", "--x.baz", "false"], {"x.foo": 10.1, "x.bar": True, "x.baz": False}) + (["--x.foo", "--x.bar=baz"], {"x.foo": True, "x.bar": "baz"}), + (["--x.foo", "10.1", "--x.bar", "--x.baz", "false"], {"x.foo": 10.1, "x.bar": True, "x.baz": False}), + (["--x.foo", "10.1", "--x.bar", "--x.baz=false"], {"x.foo": 10.1, "x.bar": True, "x.baz": False}) # fmt: on ], )