-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Do not execute anything if command line is invalid #222
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
Comments
I found another MWE. #!/usr/bin/env python
import fire
def my_fun(arg1, arg2, *, arg3="default"):
print(arg1, arg2, arg3)
if __name__ == "__main__":
fire.Fire() Execution gives: $ /tmp/mwe.py my_fun arg1 arg2 --arg4 foo
arg1 arg2 default
ERROR: Could not consume arg: --arg4
Usage: mwe.py my_fun arg1 arg2
For detailed information on this command, run:
mwe.py my_fun arg1 arg2 --help Again, the function is executed albeit the invocation is quite obviously invalid. |
The reason this doesn't work today is that Fire supports method chaining. This is the same issue raised in #168. As noted there, there may be a potential fix.
We are also thinking through a "strict mode" for fire, which uses annotations and default values to do type checking. In strict mode, it would be possible to provide better protections against the issue you raise too. |
Issue #168 explains this quite nicely. However, I think some improvement on this would be desirable. After all, I am using a CLI framework not only because it is convenient to use, but also because I hope to gain some early error detection. |
In certain circumstances Fire will execute python code albeit the command line is not valid. Consider the following MWE:
If I execute it with
I get
Note that the function is executed anyways.
In my case this behaviour let a bug manifest in a CI pipeline. I would have preferred to see the step break directly.
The text was updated successfully, but these errors were encountered: