Skip to content
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

Unexpected Completion Behavior #148

Open
tschwaller opened this issue Oct 27, 2018 · 5 comments
Open

Unexpected Completion Behavior #148

tschwaller opened this issue Oct 27, 2018 · 5 comments

Comments

@tschwaller
Copy link

tschwaller commented Oct 27, 2018

Consider the following simple example (from the docs)

#!/usr/bin/env python

import fire

def add(x, y):
  return x + y

if __name__ == '__main__':
  fire.Fire(add, name='./add.py')

The first command completion shows add and the second immediately --x --y.

This is confusing, since I would expect to see X and after I entered the first number I would expect Y or or even X Y at the very beginning so I know I have to enter 2 numbers, especially since the Usage shows

Usage:       ./add.py X Y
             ./add.py --x X --y Y

As far as I can see it is also not possible to distinguish mandatory from optional arguments. In the case above X and Yare mandatory and I would not expect to see --xand --y. An optional argument could e.g. be --modulo, which would have a default value if not used, but how to distinguish that in the Python code from the other arguments?

@dbieber
Copy link
Member

dbieber commented Oct 27, 2018

Good point about the order, thanks for bringing this up.
As for mandatory vs optional args, optional args (those with default values) should be shown in square brackets in the help screen.
We're actively working on improving the help and usage screens. The tab completion also has room for improvement, but isn't actively being worked on.

@tschwaller
Copy link
Author

tschwaller commented Oct 27, 2018

Thanks for input. Ah, yes, something like

def add(x, y=0):

shows

Usage:       ./add.py X [Y]
             ./add.py --x X [--y Y]

and should actually not show --x X but Xin both cases since this is mandatory. Although the command completion might look like a minor feature, it is actually one of the killer features of python-fire since it works out of the box (#32, #98 will make that even better when implemented). The more natural the completion, the better! 👍

P.S. ./add.py -- --help is also kind of unnatural. There should be an exception for that, so you could always say e.g. ./add.py --help and ./add.py add --helpwhich would give the commands and its completions a very natural behavior. just my 2 cents.

@dbieber
Copy link
Member

dbieber commented Oct 28, 2018

P.S. ./add.py -- --help is also kind of unnatural.

Yes! We now support just ./add.py --help as well (and as of a few commits ago, ./add.py -h as well). Now the only time this won't work is if the function has a parameter named help.

@stefaang
Copy link

stefaang commented May 28, 2019

Found another minor one: when using classes, the completion should not suggest the self argument.

@bluedistro
Copy link

Found another minor one: when using classes, the completion should not suggest the self argument.

I think this issue is resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants