diff --git a/news/434.bugfix.md b/news/434.bugfix.md new file mode 100644 index 00000000..7ebde17e --- /dev/null +++ b/news/434.bugfix.md @@ -0,0 +1 @@ +Fixed `parameter_option` returning only the first character of `--option=value` and attached short-option values. diff --git a/src/cleo/io/inputs/argv_input.py b/src/cleo/io/inputs/argv_input.py index 54cc1735..710fa544 100644 --- a/src/cleo/io/inputs/argv_input.py +++ b/src/cleo/io/inputs/argv_input.py @@ -129,8 +129,8 @@ def parameter_option( # For short options, test for '-o' at beginning leading = value + "=" if value.startswith("--") else value - if token == value or (leading != "" and token.startswith(leading)): - return token[len(leading)] + if leading != "" and token.startswith(leading): + return token[len(leading) :] return False diff --git a/tests/io/inputs/test_argv_input.py b/tests/io/inputs/test_argv_input.py index f83ae50f..54561fd3 100644 --- a/tests/io/inputs/test_argv_input.py +++ b/tests/io/inputs/test_argv_input.py @@ -151,3 +151,26 @@ def test_parse_options( i.bind(Definition(options)) assert i.options == expected_options + + +@pytest.mark.parametrize( + ["args", "values", "expected"], + [ + (["cli.py", "--directory", "/tmp/foo"], "--directory", "/tmp/foo"), + (["cli.py", "--directory=/tmp/foo"], "--directory", "/tmp/foo"), + (["cli.py", "-C", "/tmp/foo"], "-C", "/tmp/foo"), + (["cli.py", "-C/tmp/foo"], "-C", "/tmp/foo"), + ( + ["cli.py", "run", "--directory=/tmp/foo", "python"], + "--directory", + "/tmp/foo", + ), + (["cli.py", "run", "-C/tmp/foo", "python"], "-C", "/tmp/foo"), + ], +) +def test_parameter_option_returns_full_attached_value( + args: list[str], values: str, expected: str +) -> None: + i = ArgvInput(args) + + assert i.parameter_option(values) == expected