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

Migrate cli implementation from clap to structopt #8027

Merged

Conversation

sajjaphani
Copy link
Contributor

@sajjaphani sajjaphani commented Dec 4, 2020

#7866

Removes the clap parsing logic and implements the struct opt cli implementations.

Signed-off-by: Phani Sajja <[email protected]>
Signed-off-by: Phani Sajja <[email protected]>
@sajjaphani
Copy link
Contributor Author

Removed all the clap_app macro invocations of clap and converted the options into structopt structures. The remaining work related to consuming the Structure returned by structopt will be taken into a separate PR.

Copy link
Contributor

@christophermaier christophermaier left a comment

Choose a reason for hiding this comment

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

A few changes to make, but overall this looks good! I think with this we can remove the feature flag for a structopt CLI, since that's now the only choice.

"Export either the 'public' or 'secret' key. The 'secret' key is the origin private key")
(arg: arg_cache_key_path())
)
(subcommand: OritinKeyExport::clap().aliases(&["e", "ex", "exp", "expo", "expor"]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Spelling error on OritinKeyExport

components/hab/src/cli.rs Outdated Show resolved Hide resolved
components/hab/src/cli.rs Outdated Show resolved Hide resolved
components/hab/src/cli.rs Outdated Show resolved Hide resolved
(subcommand: alias_term)
(after_help: AFTER_HELP)
)
Options::clap()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not the same as Hab::clap() above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, here is the updated code.

pub fn get(feature_flags: FeatureFlag) -> App<'static, 'static> {
    if feature_flags.contains(FeatureFlag::STRUCTOPT_CLI) {
        return Hab::clap();
    }

    Options::clap()
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Originally, when we were first rolling out structopt to represent parts of the CLI, we hid it behind a feature flag so users could opt in and give feedback, but if anything went wrong, there was an "escape hatch".

Now, however, the CLI is only going to be implemented using structopt. In that case, it seems that Hab::clap() and Options::clap() are going to be the same. Thus, Options is basically a duplicate of Hab, which means we don't need Options at all. It furthermore implies that we can remove the STRUCTOPT_CLI feature flag altogether.

Are there meaningful differences between Hab and Options, or can the latter be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see some aliases are being explicitly set on certain subcommands, which are not present in Hab::clap() part, and also see some settings are being set settings = &[AppSettings::ArgRequiredElseHelp, AppSettings::SubcommandRequiredElseHelp]

Signed-off-by: Phani Sajja <[email protected]>
Signed-off-by: Phani Sajja <[email protected]>
Signed-off-by: Phani Sajja <[email protected]>
Copy link
Contributor

@christophermaier christophermaier left a comment

Choose a reason for hiding this comment

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

I have one comment, but otherwise I think this looks good. Thanks for tackling this!

Comment on lines 18 to 37
use self::{bldr::{ChannelCreate,
ChannelDemote,
ChannelDestroy,
ChannelList,
ChannelPromote,
ConfigOptChannelCreate,
ConfigOptChannelDemote,
ConfigOptChannelDestroy,
ConfigOptChannelList,
ConfigOptChannelPromote,
ConfigOptJobCancel,
ConfigOptJobDemote,
ConfigOptJobPromote,
ConfigOptJobStart,
ConfigOptJobStatus,
JobCancel,
JobDemote,
JobPromote,
JobStart,
JobStatus},
Copy link
Contributor

Choose a reason for hiding this comment

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

While I generally dislike * imports as a rule, I think it could be helpful for the use statements that we've got in this corner of the code, simply because of the sheer volume of imports, as well as the fact that many of those imports are auto-generated ConfigOpt ones, which tends to make things look a bit confusing.

So, this highlighted code could be collapsed to use self::bldr::*, with similar replacements for the other module declarations, both in this file and in others that this PR is touching.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree in this case!

@sajjaphani sajjaphani marked this pull request as ready for review December 11, 2020 14:07
@sajjaphani sajjaphani requested a review from markan as a code owner December 11, 2020 14:07
@sajjaphani sajjaphani changed the title Psajja/migrate to structopt Migrate cli implementation from clap to structopt Dec 11, 2020
@christophermaier christophermaier merged commit 471cf05 into habitat-sh:master Dec 15, 2020
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