Skip to content

Commit

Permalink
Fixed an issue in parsing of EngineKind
Browse files Browse the repository at this point in the history
`--engine` was not getting correctly parsed as `EngineKind` but was
getting parsed as a `String`. This was happening because `value_parser`
set initially was getting overwritten (in the original code).

This caused a runtime `panic!`. Fixed, works properly.

Signed-off-by: Abhijit Gadgil <[email protected]>
  • Loading branch information
agadgil-progress committed Jul 16, 2024
1 parent 5d2d8f2 commit 784bb71
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions components/pkg-export-container/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ 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<()> {
if matches.get_one::<String>("ENGINE") == Some(&"buildah".to_owned())
if matches.get_one::<EngineKind>("ENGINE") == Some(&EngineKind::Buildah)
&& matches.get_flag("MULTI_LAYER")
{
return Err(EngineError::BuildahIncompatibleWithMultiLayer.into());
Expand All @@ -65,7 +65,7 @@ pub fn fail_if_buildah_and_multilayer(matches: &ArgMatches) -> Result<()> {
}

/// Things that can build containers!
#[derive(Clone, Copy, Debug, Default, clap::ValueEnum)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, clap::ValueEnum)]
enum EngineKind {
#[default]
Docker,
Expand Down Expand Up @@ -116,8 +116,7 @@ pub fn cli_arg() -> Arg {
// Since there is effectively no choice of engine for
// Windows, we hide the CLI option and don't document it
// any further.
arg.value_parser(["docker"])
.hide(true)
arg.hide(true)
} else {
arg.long_help(
"Using the `docker` engine allows you to use Docker to create
Expand All @@ -135,16 +134,14 @@ Please see https://buildah.io for more details.
Both engines create equivalent container images.
",
)
.value_parser(["docker", "buildah"])
}
}

impl TryFrom<&ArgMatches> for Box<dyn Engine> {
type Error = anyhow::Error;

fn try_from(value: &ArgMatches) -> StdResult<Self, Self::Error> {
let engine = value.get_one::<String>("ENGINE").unwrap();
let engine = EngineKind::from_str(engine).unwrap();
let engine = value.get_one::<EngineKind>("ENGINE").unwrap();
match engine {
EngineKind::Docker => Ok(Box::new(docker::DockerEngine::new()?)),
#[cfg(not(windows))]
Expand Down

0 comments on commit 784bb71

Please sign in to comment.