diff --git a/CHANGES.rst b/CHANGES.rst index 453bc40..426a56d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,14 @@ Changelog ~~~~~~~~~ +Version 0.30.3 (2023-10-30) +--------------------------- + +Bugs fixed: + +- Regression: a positional argument with an underscore used in `@arg` decorator + would cause Argh fail on the assembling stage. (#208) + Version 0.30.2 (2023-10-24) --------------------------- diff --git a/pyproject.toml b/pyproject.toml index 92a3906..26c7cce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi" [project] name = "argh" -version = "0.30.2" +version = "0.30.3" description = "An unobtrusive argparse wrapper with natural syntax" readme = "README.rst" requires-python = ">=3.8" diff --git a/src/argh/decorators.py b/src/argh/decorators.py index aad081b..10ede10 100644 --- a/src/argh/decorators.py +++ b/src/argh/decorators.py @@ -141,10 +141,11 @@ def wrapper(func: Callable) -> Callable: raise CliArgToFuncArgGuessingError("at least one CLI arg must be defined") func_arg_name = naive_guess_func_arg_name(args) + cli_arg_names = [name.replace("_", "-") for name in args] completer = kwargs.pop("completer", None) spec = ParserAddArgumentSpec.make_from_kwargs( func_arg_name=func_arg_name, - cli_arg_names=args, + cli_arg_names=cli_arg_names, parser_add_argument_kwargs=kwargs, ) if completer: diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 7ac1d84..b813069 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -33,7 +33,7 @@ def func(): assert attrs == [ ParserAddArgumentSpec( func_arg_name="foo", - cli_arg_names=("foo",), + cli_arg_names=["foo"], nargs="+", other_add_parser_kwargs={ "help": "my help", @@ -41,7 +41,7 @@ def func(): ), ParserAddArgumentSpec( func_arg_name="bar", - cli_arg_names=("--bar",), + cli_arg_names=["--bar"], default_value=1, ), ] diff --git a/tests/test_integration.py b/tests/test_integration.py index b2f392d..e70db4f 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -735,14 +735,21 @@ def remind( parser = DebugArghParser() parser.set_default_command(remind) - assert "Basil" in parser.format_help() - assert "Moose" in parser.format_help() - assert "creatures" in parser.format_help() - - # explicit help message is not obscured by the implicit one... - assert "remarkable animal" in parser.format_help() - # ...but is still present - assert "it can speak" in parser.format_help() + help_normalised = re.sub(r"\s+", " ", parser.format_help()) + + assert "name 'Basil'" in help_normalised + assert "-t TASK, --task TASK 'hang the Moose'" in help_normalised + assert ( + "-r REASON, --reason REASON 'there are creatures living in it'" + in help_normalised + ) + + # explicit help message is not obscured by the implicit one + # but is still present + assert ( + "-n NOTE, --note NOTE why is it a remarkable animal? " + "(default: 'it can speak English')" + ) in help_normalised def test_default_arg_values_in_help__regression(): diff --git a/tests/test_regressions.py b/tests/test_regressions.py index bb49e70..c19115f 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -171,3 +171,12 @@ def func(*, x: TextIO = sys.stdout) -> None: parser = DebugArghParser() parser.set_default_command(func) + + +def test_regression_issue208(): + @argh.arg("foo_bar", help="fooooo") + def func(foo_bar): + return foo_bar + + parser = DebugArghParser() + parser.set_default_command(func)