Skip to content

Commit

Permalink
Review Comments: Mostly usage update
Browse files Browse the repository at this point in the history
- Removed '(default: ..)' from the help text of args where it is
  available from `clap`.
- Fixed 'author' and 'usage' in the `help_template`
- Fixed windows build failure behind `cfg(not(windows))`

Signed-off-by: Abhijit Gadgil <[email protected]>
  • Loading branch information
agadgil-progress committed Jul 17, 2024
1 parent 784bb71 commit ad15be5
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 89 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions components/pkg-export-container/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ doc = false

[dependencies]
base64 = "*"
#clap = { git = "https://github.com/habitat-sh/clap.git", branch = "v2-master", features = ["suggestions", "color", "unstable"] }
clap = { version = "4" , features = ["env", "derive", "string"]}
clap = { version = "4" , features = ["env", "derive", "string", "wrap_help"]}
env_logger = "*"
hab = { path = "../hab" }
habitat_common = { path = "../common" }
Expand Down
122 changes: 50 additions & 72 deletions components/pkg-export-container/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ pub fn cli() -> Command {
let about = "Creates a container image from a set of Habitat packages (and optionally pushes \
to a remote repository)";

let cmd = Command::new(name).about(about)
.version(VERSION)
.author("\nThe Habitat Maintainers <[email protected]>")
.help_template("{name} {version} {author-section} {about-section} \
\n{usage-heading}\n\n{all-args}")
.arg(Arg::new("IMAGE_NAME").long("image-name")
.short('i')
.value_name("IMAGE_NAME")
.help("Image name (default: \
{{pkg_origin}}/{{pkg_name}} \
supports: {{pkg_origin}}, \
{{pkg_name}}, {{pkg_version}}, \
{{pkg_release}}, {{channel}})"));
let cmd =
Command::new(name).max_term_width(80)
.about(about)
.version(VERSION)
.author("\nAuthors: The Habitat Maintainers <[email protected]>")
.help_template("{name} {version} {author-section} {about-section} \
\n{usage-heading} {usage}\n\n{all-args}")
.arg(Arg::new("IMAGE_NAME").long("image-name")
.short('i')
.value_name("IMAGE_NAME")
.help("Image name template: supports: \
{{pkg_origin}}/{{pkg_name}} \
{{pkg_origin}}, {{pkg_name}}, \
{{pkg_version}}, {{pkg_release}}, \
{{channel}})")
.default_value("{{pkg_origin/pkg_name}}"));

let cmd = add_base_packages_args(cmd);
let cmd = add_builder_args(cmd);
Expand Down Expand Up @@ -59,7 +62,7 @@ fn add_base_packages_args(cmd: Command) -> Command {
.help(
"Habitat CLI package identifier (ex: acme/redis) or filepath to a Habitat \
artifact (ex: /home/acme-redis-3.0.7-21120102031201-x86_64-linux.hart) \
to install (default: core/hab)",
to install",
),
)
.arg(
Expand All @@ -72,7 +75,7 @@ fn add_base_packages_args(cmd: Command) -> Command {
"Launcher package identifier (ex: core/hab-launcher) or filepath to a \
Habitat artifact (ex: \
/home/core-hab-launcher-13829-20200527165030-x86_64-linux.hart) to \
install (default: core/hab-launcher)",
install",
),
)
.arg(
Expand All @@ -84,91 +87,66 @@ fn add_base_packages_args(cmd: Command) -> Command {
.help(
"Supervisor package identifier (ex: core/hab-sup) or filepath to a \
Habitat artifact (ex: \
/home/core-hab-sup-1.6.39-20200527165021-x86_64-linux.hart) to install \
(default: core/hab-sup)",
/home/core-hab-sup-1.6.39-20200527165021-x86_64-linux.hart) to install",
),
)
}

fn add_builder_args(cmd: Command) -> Command {
cmd.arg(
Arg::new("BLDR_URL")
.long("url")
.short('u')
.value_name("BLDR_URL")
.default_value(Into::<Str>::into(default_bldr_url()))
.value_parser(UrlValueParser)
.help(
"Install packages from Builder at the specified URL \
(default: https://bldr.habitat.sh)",
),
)
.arg(
Arg::new("CHANNEL")
.long("channel")
.short('c')
.value_name("CHANNEL")
.help("Install packages from the specified release channel (default: stable)"),
)
.arg(
Arg::new("BASE_PKGS_BLDR_URL")
.long("base-pkgs-url")
.value_name("BASE_PKGS_BLDR_URL")
.default_value(Into::<Str>::into(default_bldr_url()))
.value_parser(UrlValueParser)
.help(
"Install base packages from Builder at the specified URL \
(default: https://bldr.habitat.sh)",
),
)
.arg(
Arg::new("BASE_PKGS_CHANNEL")
.long("base-pkgs-channel")
.value_name("BASE_PKGS_CHANNEL")
.help(
"Install base packages from the specified release channel \
(default: stable)",
),
)
.arg(
Arg::new("BLDR_AUTH_TOKEN")
.long("auth")
.short('z')
.value_name("BLDR_AUTH_TOKEN")
.help("Provide a Builder auth token for private pkg export"),
)
cmd.arg(Arg::new("BLDR_URL").long("url")
.short('u')
.value_name("BLDR_URL")
.default_value(Into::<Str>::into(default_bldr_url()))
.value_parser(UrlValueParser)
.help("Install packages from Builder at the specified URL"))
.arg(Arg::new("CHANNEL").long("channel")
.short('c')
.value_name("CHANNEL")
.default_value("stable")
.help("Install packages from the specified release channel"))
.arg(Arg::new("BASE_PKGS_BLDR_URL").long("base-pkgs-url")
.value_name("BASE_PKGS_BLDR_URL")
.default_value(Into::<Str>::into(default_bldr_url()))
.value_parser(UrlValueParser)
.help("Install base packages from Builder at the \
specified URL"))
.arg(Arg::new("BASE_PKGS_CHANNEL").long("base-pkgs-channel")
.value_name("BASE_PKGS_CHANNEL")
.default_value("stable")
.help("Install base packages from the specified release"))
.arg(Arg::new("BLDR_AUTH_TOKEN").long("auth")
.short('z')
.value_name("BLDR_AUTH_TOKEN")
.help("Provide a Builder auth token for private pkg export"))
}

fn add_tagging_args(cmd: Command) -> Command {
cmd.arg(Arg::new("TAG_VERSION_RELEASE").long("tag-version-release")
.conflicts_with("NO_TAG_VERSION_RELEASE")
.action(ArgAction::SetTrue)
.help("Tag image with \
:\"{{pkg_version}}-{{pkg_release}}\" (default: \
yes)"))
:\"{{pkg_version}}-{{pkg_release}}\""))
.arg(Arg::new("NO_TAG_VERSION_RELEASE").long("no-tag-version-release")
.conflicts_with("TAG_VERSION_RELEASE")
.action(ArgAction::SetTrue)
.help("Do not tag image with \
:\"{{pkg_version}}-{{pkg_release}}\" \
(default: no)"))
:\"{{pkg_version}}-{{pkg_release}}\""))
.arg(Arg::new("TAG_VERSION").long("tag-version")
.conflicts_with("NO_TAG_VERSION")
.action(ArgAction::SetTrue)
.help("Tag image with :\"{{pkg_version}}\" (default: yes)"))
.help("Tag image with :\"{{pkg_version}}\""))
.arg(Arg::new("NO_TAG_VERSION").long("no-tag-version")
.conflicts_with("TAG_VERSION")
.action(ArgAction::SetTrue)
.help("Do not tag image with :\"{{pkg_version}}\" \
(default: no)"))
.help("Do not tag image with :\"{{pkg_version}}\""))
.arg(Arg::new("TAG_LATEST").long("tag-latest")
.conflicts_with("NO_TAG_LATEST")
.action(ArgAction::SetTrue)
.help("Tag image with :\"latest\" (default: yes)"))
.help("Tag image with :\"latest\""))
.arg(Arg::new("NO_TAG_LATEST").long("no-tag-latest")
.conflicts_with("TAG_LATEST")
.action(ArgAction::SetTrue)
.help("Do not tag image with :\"latest\" (default: no)"))
.help("Do not tag image with :\"latest\""))
.arg(Arg::new("TAG_CUSTOM").long("tag-custom")
.value_name("TAG_CUSTOM")
.help("Tag image with additional custom tag (supports: \
Expand Down
29 changes: 14 additions & 15 deletions components/pkg-export-container/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ enum EngineError {
/// When https://github.com/containers/buildah/issues/2215 is fixed,
/// we can update our Buildah dependency and remove this check.
pub fn fail_if_buildah_and_multilayer(matches: &ArgMatches) -> Result<()> {
#[cfg(not(windows))]
if matches.get_one::<EngineKind>("ENGINE") == Some(&EngineKind::Buildah)
&& matches.get_flag("MULTI_LAYER")
{
return Err(EngineError::BuildahIncompatibleWithMultiLayer.into());
}

Ok(())
}

Expand Down Expand Up @@ -118,21 +120,18 @@ pub fn cli_arg() -> Arg {
// any further.
arg.hide(true)
} else {
arg.long_help(
"Using the `docker` engine allows you to use Docker to create
your container images. You must ensure that a Docker daemon
is running on the host where this command is executed, and
that the user executing the command has permission to access
the Docker socket.
Using the `buildah` engine allows you to create container images
as an unprivileged user, and without having to use a Docker
daemon. This is the recommended engine for use in CI systems and
other environments where security is of particular concern.
Please see https://buildah.io for more details.
Both engines create equivalent container images.
",
arg.long_help("Using the `docker` engine allows you to use Docker to create \
your container images. You must ensure that a Docker daemon \
is running on the host where this command is executed, and \
that the user executing the command has permission to access \
the Docker socket.\n\n\
Using the `buildah` engine allows you to create container images \
as an unprivileged user, and without having to use a Docker \
daemon. This is the recommended engine for use in CI systems and \
other environments where security is of particular concern. \
Please see https://buildah.io for more details.\n\n\
Both engines create equivalent container images. \
",
)
}
}
Expand Down

0 comments on commit ad15be5

Please sign in to comment.