-
Notifications
You must be signed in to change notification settings - Fork 669
Improve CLI help #733
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
Hi @xarx00 I started looking at other solutions for argument parsing a few days ago but didn't have time to test. I don't have experience at all with click but we probably reached the limits of argparse as you mentioned. I say +1 to switching to something else. |
Some reference: https://realpython.com/comparing-python-command-line-parsing-libraries-argparse-docopt-click/. I have an experience with Docopt (also tested in the link), and while it is a good library, it is suited for small scripts. I have looked also on other options suggested in discussions, but Click came out as a clean winner. |
Since we now have #456 fixed, and we have #1461 to discuss our plans to switch to click, I'd say we can maybe close this one since this is quite old and continue discussion in the other issue where there is more activity. Feel free to reopen @xarx00 if this is still something you're still interested in implementing in 2022 - though obviously this will take quite a bit of work. |
Description of the problem, including code/CLI snippet
There's a lot of issues for the CLI help, which makes it difficult to use the CLI at all. Some of them have been already reported:
--help
does not work properly on sub-commands (gitlab CLI --help not working as expected #381, mostly resolved by Re-enable command specific help messages #732)But there are others, for instance:
gitlab group list -x
), general usage (forgitlab
) is printed by gitlab CLI instead of specific usage for the used action (i.e.gitlab group list
).Gitlab uses
argparse
for argument parsing and help output. Most of these problems (2. and 3. in particular) seem to be caused by the limitations of theargparse
library. I was trying to persuadeargparse
to provide better help, but I was not able to do that. Most of this bad behaviour is hard-coded in the library, and cannot be changed. The public API is limited, the rest of the API "are considered implementation details".I'm not an expert for
argparse
, so I may be wrong, but the help seems to me unfixable while it is based onargparse
. Instead I suggest switching toclick
. I was playing withclick
, and I was able to configure it so that its help output looks very good even for a script like gitlab. See demo comparison.zip, that compares help output ofargparse
andclick
in various situations. In the comparison, note:argparse output is appropriate to the arguments in all tests but the last two.
argparse output looks confusing especially when there are lots of commands (I've counted 27 rows of commands on 80 character console, and this list is printed twice)
argparse output cannot be customized
click output looks more standard
click output can be simply customized (as seen e.g. in demo_click2.py)
Resume
I'd like to know your opinion on this suggested change. I won't be doing anything concerning the migration towards
click
untill it is clear that the change will be welcome.Specifications
The text was updated successfully, but these errors were encountered: