BrianPugh/cyclopts

Use of the meta application results in a double help display

pythoninja opened this issue · 5 comments

Hi,

I am moving from the Typer and have some strange behavior. Please, consider this test application:

from typing import Annotated

from cyclopts import App, Group
from cyclopts import Parameter

__app_name__ = "Test app"
__version__ = "0.0.1"

app = App(version=f"{__app_name__} v{__version__}", version_flags=["--version"], help_flags=["--help"])
app.meta.group_parameters = Group("Debug Output")


@app.command
def foo(h_param: Annotated[str, Parameter(name=["-h", "--hparam"], allow_leading_hyphen=True)] = "some_value"):
    print("h_param", h_param)


@app.meta.default()
def main(*tokens: Annotated[str, Parameter(show=False, allow_leading_hyphen=True)],
         verbose: Annotated[bool, Parameter(name="--verbose", show_default=False, negative="")] = False):
    if verbose:
        print("verbose mode enabled")
    else:
        print("verbose mode disabled")

    app(tokens)


if __name__ == "__main__":
    app.meta()

Then the following happens:

python cli2.py

verbose mode disabled
Usage: cli2.py COMMAND

╭─ Commands ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ foo                                                                                                                                                                                       │
│ --help,-h  Display this message and exit.                                                                                                                                                 │
│ --help     Display this message and exit.                                                                                                                                                 │
│ --version  Display application version.                                                                                                                                                   │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Debug Output ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --verbose                                                                                                                                                                                 │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

And this:

python cli2.py --verbose foo -h 111

Usage: cli2.py COMMAND

╭─ Commands ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ foo                                                                                                                                                                                       │
│ --help,-h  Display this message and exit.                                                                                                                                                 │
│ --help     Display this message and exit.                                                                                                                                                 │
│ --version  Display application version.                                                                                                                                                   │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Debug Output ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --verbose                                                                                                                                                                                 │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

But if I change -h to --hparam it works as expected:

python cli2.py --verbose foo --hparam 222

verbose mode enabled
h_param 222

Please help me to remove double --help from the output, and -h should also work as a short option.

Thank you!

This is certainly an issue! I'll try and have a reasonable fix in soon!

Please give #127 a try. I think your code actually requires no changes.

I think your code actually requires no changes

This is true. Looks like, it works now in the expected way. Thank you!

Awesome! I plan on merging and making a release later today; I want to clean up the PR a little bit.

This is released in v2.4.2. I'm working on fixing the other bug mentioned in #127, just publishing this now incase it takes me longer than expected and so I don't unnecessarily block you.