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

Use argparse subparsers for subcommands #80

Merged
merged 1 commit into from
Apr 3, 2019
Merged

Use argparse subparsers for subcommands #80

merged 1 commit into from
Apr 3, 2019

Conversation

csomh
Copy link
Contributor

@csomh csomh commented Mar 21, 2019

Makes argument parsing more resilient, by handling
subcommands with argparse provided and recommended subparsers,
instead of the current custom manipulation of argv.

Removes the need to manually update and format the top-level
help message: this is going to be composed from the help strings
of the subcommands by argparse.

Fixes the issue of subcommand's usage string not displaying the
subcommand.

Removes the need to explicitly check for incorrect subcommands.

Enables extending the CLI with top-level optional arguments, without the
need of adjusting argv parsing.

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 21, 2019
@openshift-ci-robot
Copy link

Hi @csomh. Thanks for your PR.

I'm waiting for a operator-framework or openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@kevinrizza
Copy link
Member

What is the advantage of using subcommand versus the current implementation?

Also, #77 should be solved by a separate pr. Please do not co-mingle multiple changes in a single pull request.

@csomh
Copy link
Contributor Author

csomh commented Mar 21, 2019

Subparsers are the argparse provided way to handle subcommands. Switching to this was easier than figuring out the bug in the custom implementation, which was causing #77 or led to an incorrect usage text to be displayed for subcommands.

Sorry, the commit message didn't clarify this. Updated it, together with the initial PR comment.

@kevinrizza
Copy link
Member

How do you know that there was a bug at all? It seems like the command has description output, and I'm not sure that your change fixed any bug at all. It seems more likely to me that the issue in question was describing a perceived lack of documentation about what the flag outputs (aside from the very basic description of the flag).

That could be a separate discussion, but I don't think this PR fixes the issue.

And, again, I still don't see what using subcommands contributes here. Is there some design limitation to the current implementation (aside from not using some specific sub library)? What does moving to using subcommand actually give us that we don't have already? If there is a technical argument to be made for them, I am certainly interested in hearing it.

@csomh
Copy link
Contributor Author

csomh commented Mar 21, 2019

Oh, ok, I see now. You're right.

@csomh csomh closed this Mar 21, 2019
@MartinBasti
Copy link
Contributor

This PR is still valid (but must be updated), There were already several issues caused by not using subparsers.

@MartinBasti MartinBasti reopened this Mar 29, 2019
Copy link
Member

@kevinrizza kevinrizza left a comment

Choose a reason for hiding this comment

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

Please update the commit message to stop referencing #77 since this does not resolve the issue, and please give a more detailed description of what problems this implementation resolves.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 2, 2019
Makes argument parsing more resilient, by handling
subcommands with argparse provided and recommended [subparsers][1],
instead of the current custom manipulation of argv.

Removes the need to manually update and format the top-level
help message: this is going to be composed from the help strings
of the subcommands by argparse.

Fixes the issue of subcommand's usage string not displaying the
subcommand.

Removes the need to explicitly check for incorrect subcommands.

Enables extending the CLI with top-level optional arguments, without the
need of adjusting argv parsing.

[1]: https://docs.python.org/3/library/argparse.html#sub-commands

Signed-off-by: Hunor Csomortáni <[email protected]>
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 2, 2019
@csomh
Copy link
Contributor Author

csomh commented Apr 2, 2019

Updated.

@kevinrizza
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 3, 2019
@MartinBasti
Copy link
Contributor

works for me

@kevinrizza kevinrizza merged commit e9e36ad into operator-framework:master Apr 3, 2019
@csomh csomh deleted the use-subparsers branch April 15, 2019 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants