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

Add behavior like no-args-is-help to commands #637

Merged
merged 1 commit into from
May 13, 2022

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented May 13, 2022

Unlike the builtin no_args_is_help option, we do not want this behavior to trigger on commands which take no arguments (all args are optional).

In our custom command class, override the behavior of parse_args to check for MissingParameter errors combined with an empty arg list. Such a situation indicates that a command requires arguments (e.g. globus transfer) and none were given. In this situation, print the MissingParameter error message, followed by the full helptext for the current command, then exit(2) .

If there were arguments and a MissingParameter error is encountered, just reraise and trust click to handle it as normal.


@rudyardrichter, we discussed the variant of this in timer-cli. I considered that and almost lifted it into here. I didn't really like handling other errors beyond MissingParameter (easy to tweak), so I cut it down. But then I had to construct artificial Groups for my testing to ensure there would be a parent context (because that approach catches the errors outside of make_context). That "felt wrong" and manually touching usage parts with the help formatter was fiddly, so I started looking at the no_args_is_help implementation. That looks like a good place to hook in, so this is just wrapping the click behavior with a little bit of extra handling.

Unlike the builtin no_args_is_help option, we do not want this
behavior to trigger on commands which take no arguments (all args are
optional).

In our custom command class, override the behavior of `parse_args` to
check for MissingParameter errors combined with an empty arg list.
Such a situation indicates that a command requires arguments (e.g.
`globus transfer`) and none were given. In this situation, print the
MissingParameter error message, followed by the full helptext for the
current command, then exit(2) .

If there were arguments and a MissingParameter error is encountered,
just reraise and trust click to handle it as normal.
@sirosen sirosen force-pushed the improve-cmd-help branch from 5e30384 to 7a4c805 Compare May 13, 2022 16:11
Copy link
Contributor

@rudyardrichter rudyardrichter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Glad to see this added.

@sirosen sirosen merged commit 9b59e7b into globus:main May 13, 2022
@sirosen sirosen deleted the improve-cmd-help branch May 13, 2022 16:24
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

Successfully merging this pull request may close these issues.

2 participants