Document how to provide a negative number as an argument #798
Unanswered
ricardogsilva
asked this question in
Questions
Replies: 1 comment
-
Thank you for your message and for the inconsistency found in the Typer documentation. Indeed, there is no mention in the Typer documentation of the need to use the context_settings={"ignore_unknown_options": True} context parameter to correctly handle negative numbers on the command line. I suggest adding this point to the documentation so that other users can also avoid similar difficulties. Your code example demonstrates the correct way to handle negative numbers on the command line using Typer. If you encounter any other questions or problems, please let me know and I will try to help you. |
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
-
First Check
Commit to Help
Example Code
Description
Using a negative number as an argument needs some special crafting in order to work.
If you try calling the above with a negative number, you'll get an error like this:
The respective click docs mention two strategies:
Option 1 - use --- as a separator
Quoting the click docs:
This option does not seem to work on Typer - I'm not sure whether this is a bug or not - maybe it could be a missing feature?
Option 2 - pass ignore_unknown_options to context
This does work with Typer, as demonstrated in the code snippet I pasted above, as if you change the invocation to run the
working-good
command you get:In my opinion the Typer docs should mention this in the CLI Parameter types - Number section - it would have saved me a bunch of time if it did 😉
Operating System
Linux
Operating System Details
No response
Typer Version
0.12.3
Python Version
3.10.12
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions