Use of the meta application results in a double help display
pythoninja opened this issue · 5 comments
pythoninja commented
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!
BrianPugh commented
This is certainly an issue! I'll try and have a reasonable fix in soon!
pythoninja commented
I think your code actually requires no changes
This is true. Looks like, it works now in the expected way. Thank you!
BrianPugh commented
Awesome! I plan on merging and making a release later today; I want to clean up the PR a little bit.