Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/434.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed `parameter_option` returning only the first character of `--option=value` and attached short-option values.
4 changes: 2 additions & 2 deletions src/cleo/io/inputs/argv_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions tests/io/inputs/test_argv_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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