From 6dd97a5f6e95e6ce6e148698bd4433d0313846f1 Mon Sep 17 00:00:00 2001 From: SeaStar Deng Date: Fri, 14 Aug 2026 18:39:58 +0000 Subject: [PATCH 1/2] Fix parameter_option returning only the first character of attached values. ArgvInput.parameter_option used token[len(leading)] instead of a slice, so --directory=/tmp/foo and -C/tmp/foo each returned a single character. This matches Symfony's substr() and unblocks poetry run --directory=path. --- news/434.bugfix.md | 1 + src/cleo/io/inputs/argv_input.py | 4 ++-- tests/io/inputs/test_argv_input.py | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 news/434.bugfix.md 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..0a78ffca 100644 --- a/tests/io/inputs/test_argv_input.py +++ b/tests/io/inputs/test_argv_input.py @@ -151,3 +151,23 @@ 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 From afce3e95f30fc35400efa9848fe6f3b468572575 Mon Sep 17 00:00:00 2001 From: SeaStar Deng Date: Fri, 14 Aug 2026 18:41:30 +0000 Subject: [PATCH 2/2] Format parameter_option tests to satisfy ruff. --- tests/io/inputs/test_argv_input.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/io/inputs/test_argv_input.py b/tests/io/inputs/test_argv_input.py index 0a78ffca..54561fd3 100644 --- a/tests/io/inputs/test_argv_input.py +++ b/tests/io/inputs/test_argv_input.py @@ -153,7 +153,6 @@ def test_parse_options( assert i.options == expected_options - @pytest.mark.parametrize( ["args", "values", "expected"], [ @@ -161,7 +160,11 @@ def test_parse_options( (["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", "--directory=/tmp/foo", "python"], + "--directory", + "/tmp/foo", + ), (["cli.py", "run", "-C/tmp/foo", "python"], "-C", "/tmp/foo"), ], )