-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Let's say I have some function like this:
def myfunction(arg1, arg2, run_encoding):
print(arg1, arg2, run_encoding)
fire.Fire()
If I accidentally misspell the run_encoding argument, I get behavior that can be really confusing to debug (e.g., if that's a relative file path, you suddenly get a --mypath=1 directory):
›› python fire_example.py myfunction --arg1=a --arg2=b --run-encoding=5
('a', 'b', 5)
›› python fire_example.py myfunction --arg1=a --arg2=b --runencoding=5
('a', 'b', '--runencoding=5')
I assume this happens because fire fills in all the keyword args and then assumes you specify positional arguments after them?
What I wish happened instead is that, unless explicitly quoted, any argument starting with -- would be treated as a keyword arg, so you'd see:
1. Initial component
2. Accessed property "myfunction"
3. ('The function received no value for the required argument:', 'run_encoding')
Type: function
String form: <function myfunction at 0x110138cf8>
File: /Users/jtratner/fire_example.py
Line: 3
Usage: fire_example.py myfunction ARG1 ARG2 RUN_ENCODING
fire_example.py myfunction --arg1 ARG1 --arg2 ARG2 --run-encoding RUN_ENCODING
This is related to the issue in #25, in that if positional arguments were not allowed after keyword arguments, you wouldn't end up with the ambiguity, but I can see how that's less "shell like".
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels