Replies: 3 comments 3 replies
-
The example code doesn't run. You need to apply the following diff: - run(main())
+ run(main) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Wouldn't it be simpler to just a have an optional from typing import Annotated, Optional
from typer import Option, run
def main(glob: Annotated[str, Option(help="help for glob")] = ""):
print(locals())
if __name__ == "__main__":
run(main) Examples:
|
Beta Was this translation helpful? Give feedback.
3 replies
-
Not exactly what you want, but may be a workaround in some cases: from typing import Annotated, Optional
from typer import Option, run
def main(
glob: Annotated[Optional[str], Option()] = "*",
no_glob: Annotated[bool, Option("--no-glob")] = False,
):
glob = None if no_glob is True else glob
print(glob)
if __name__ == "__main__":
run(main) Try it: $ typer myapp.py run --no-glob
None
$ typer myapp.py run
*
$ typer myapp.py run --glob something --no-glob
None
$ typer myapp.py run --help
Usage: typer [PATH_OR_MODULE] run [OPTIONS]
Run the provided Typer app.
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --glob TEXT [default: *] │
│ --no-glob │
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Example Code
Description
I'd like to be able to have
--flag
with a--no-flag
counterpart. These would be mutually exclusive (not supported per #140), and the former would accept a string (as opposed to a boolean option, which currently provides this kind of flag pair.Operating System
Linux, Windows, macOS
Operating System Details
No response
Typer Version
0.9.0
Python Version
3.9.16
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions