Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argparse abbreviation affects and breaks cmd args #167

Merged
merged 2 commits into from
Aug 28, 2024
Merged
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 src/con_duct/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ def from_argv(
cls, cli_args: Optional[list[str]] = None, **cli_kwargs: Any
) -> Arguments:
parser = argparse.ArgumentParser(
allow_abbrev=False,
description=ABOUT_DUCT,
formatter_class=CustomHelpFormatter,
)
Expand Down
16 changes: 16 additions & 0 deletions test/test_arg_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,19 @@ def test_duct_missing_cmd() -> None:
assert "duct: error: the following arguments are required: command" in str(
e.stdout
)


def test_abreviation_disabled() -> None:
"""
If abbreviation is enabled, options passed to command (not duct) are still
filtered through the argparse and causes problems.
"""
try:
subprocess.check_output(["duct", "ps", "--output"], stderr=subprocess.STDOUT)
raise AssertionError("Invocation of 'ps' should have failed")
except subprocess.CalledProcessError as e:
assert e.returncode == 1
assert "duct: error: ambiguous option: --output could match" not in str(
e.stdout
)
assert "ps [options]" in str(e.stdout)
Loading