-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Named arguments with multiple values, e.g. list[str] #264
Comments
I think I found the answer in your docs: from cyclopts import App, Parameter
from typing import Annotated
app = App()
@app.default
def main(
*,
input: Annotated[
list[str], Parameter(help="Input filename(s)", consume_multiple=True)
] = None,
) -> None:
"""Process the input files."""
if input is None:
print("Not told what to do")
return 1
elif not input:
print("Told to do nothing")
return 0
else:
print("Working:")
for file in input:
print(f"* {file}")
return 0
app() ❯ python cyclopts_demo.py --input A.txt B.txt
Working:
* A.txt
* B.txt Hooray! This deserves highlighting on https://cyclopts.readthedocs.io/en/latest/vs_typer/README.html in my opinion (as it looks to solve my number one frustration with Typer!) |
glad you were able to figure it out! Any recommendations on how to improve the docs (I'm very open to PRs as well!)? I don't think this feature is quite "bold" enough to make it to the README, but I certainly want all of Cyclopts information/features to be more readily available to users. |
I didn't mean the top level https://github.com/BrianPugh/cyclopts/blob/main/README.md but as another page under https://cyclopts.readthedocs.io/en/latest/vs_typer/README.html i.e. A sister page to entries like https://cyclopts.readthedocs.io/en/latest/vs_typer/help_defaults/README.html about the help defaults (another annoyance with typer where your defaults are better, cross reference typer issue 465). I would explicitly reference the argparse |
Got it! I'll add that soon, thanks for the recommendation! |
Addressed in #269 |
Sample code
Testing with cyclopts 3.1.1 on Python 3.12.7 on macOS.
This example works mostly as expected:
This works as a way to set an empty list:
Now with a single argument:
Passing multiple arguments this way works:
However, the natural argparse supported syntax does not:
This syntax is especially useful when combined with wildcards,
--input *.txt
for example.Is this me using cyclopts wrong, or do you have the same limitation as click and typer?
The text was updated successfully, but these errors were encountered: