From bd4281593d012e8e5b11b6c97bd40393223107a1 Mon Sep 17 00:00:00 2001 From: Abhijit Gadgil Date: Mon, 26 Aug 2024 14:13:41 +0530 Subject: [PATCH] Fixes to issues found during testing - pass 1 Signed-off-by: Abhijit Gadgil --- components/common/src/cli/clap_validators.rs | 3 +- components/hab/src/cli_v4/pkg.rs | 1 - components/hab/src/cli_v4/pkg/export.rs | 45 +++++++++++++++++--- components/hab/src/cli_v4/pkg/header.rs | 4 +- components/hab/src/cli_v4/pkg/install.rs | 5 ++- 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/components/common/src/cli/clap_validators.rs b/components/common/src/cli/clap_validators.rs index 0283ebf43b..88a30decea 100644 --- a/components/common/src/cli/clap_validators.rs +++ b/components/common/src/cli/clap_validators.rs @@ -193,7 +193,7 @@ fn parse_ref_internal(cmd: &clap_v4::Command, let val = value.to_str().unwrap().to_string(); let result = std::path::Path::new(&val); - if check_valid_file_dir_stdin(result, check_dir, check_stdin) { + if !check_valid_file_dir_stdin(result, check_dir, check_stdin) { let mut err = clap_v4::Error::new(clap_v4::error::ErrorKind::ValueValidation).with_cmd(cmd); if let Some(arg) = arg { err.insert(clap_v4::error::ContextKind::InvalidArg, @@ -208,7 +208,6 @@ fn parse_ref_internal(cmd: &clap_v4::Command, Ok(value.to_str().unwrap().to_string()) } } - /// Validate a given file is a 'toml' file or contains valid package idents only. /// /// Packages to be installed can be read from a 'toml' file or a file containing package idents diff --git a/components/hab/src/cli_v4/pkg.rs b/components/hab/src/cli_v4/pkg.rs index 71cab92396..1833a48383 100644 --- a/components/hab/src/cli_v4/pkg.rs +++ b/components/hab/src/cli_v4/pkg.rs @@ -164,7 +164,6 @@ impl PkgCommand { #[cfg(any(all(target_os = "linux", any(target_arch = "x86_64", target_arch = "aarch64")), all(target_os = "windows", target_arch = "x86_64")))] - #[clap(subcommand)] Self::Export(cmd) => cmd.do_export(ui).await, Self::Hash(opts) => opts.do_hash(), diff --git a/components/hab/src/cli_v4/pkg/export.rs b/components/hab/src/cli_v4/pkg/export.rs index 1152700832..968e114aac 100644 --- a/components/hab/src/cli_v4/pkg/export.rs +++ b/components/hab/src/cli_v4/pkg/export.rs @@ -1,11 +1,14 @@ // Implementation of `hab pkg export` command +use std::ffi::OsString; + use clap_v4 as clap; use clap::{Args, Subcommand}; -use habitat_common::ui::UI; +use habitat_common::ui::{UIWriter, + UI}; use crate::{command::pkg::export, error::Result as HabResult}; @@ -27,7 +30,7 @@ pub(crate) enum PkgExportCommand { Cf(PkgExportCommandOptions), /// Container Exporter - #[cfg(any(target_os = "macos", target_os = "windows"))] + #[cfg(any(target_os = "linux", target_os = "windows"))] Container(PkgExportCommandOptions), #[cfg(any(target_os = "linux", target_os = "windows"))] @@ -47,19 +50,47 @@ impl PkgExportCommand { pub(super) async fn do_export(&self, ui: &mut UI) -> HabResult<()> { match self { #[cfg(target_os = "linux")] - PkgExportCommand::Cf(opts) => export::cf::start(ui, &opts.args).await, + PkgExportCommand::Cf(opts) => { + export::cf::start(ui, + &opts.args + .iter() + .map(|s| OsString::from(s)) + .collect::>()).await + } #[cfg(any(target_os = "linux", target_os = "windows"))] - PkgExportCommand::Container(opts) => export::container::start(ui, &opts.args).await, + PkgExportCommand::Container(opts) => { + export::container::start(ui, + &opts.args + .iter() + .map(|s| OsString::from(s)) + .collect::>()).await + } #[cfg(any(target_os = "linux", target_os = "windows"))] PkgExportCommand::Docker(opts) => { ui.warn("'hab pkg export docker' is now a deprecated alias for 'hab pkg export \ container'. Please update your automation and processes accordingly.")?; - export::container::start(ui, &opts.args).await + export::container::start(ui, + &opts.args + .iter() + .map(|s| OsString::from(s)) + .collect::>()).await } #[cfg(target_os = "linux")] - PkgExportCommand::Mesos(opts) => export::mesos::start(ui, &opts.args).await, + PkgExportCommand::Mesos(opts) => { + export::mesos::start(ui, + &opts.args + .iter() + .map(|s| OsString::from(s)) + .collect::>()).await + } #[cfg(any(target_os = "linux", target_os = "windows"))] - PkgExportCommand::Tar(opts) => export::tar::start(ui, &opts.args).await, + PkgExportCommand::Tar(opts) => { + export::tar::start(ui, + &opts.args + .iter() + .map(|s| OsString::from(s)) + .collect::>()).await + } } } } diff --git a/components/hab/src/cli_v4/pkg/header.rs b/components/hab/src/cli_v4/pkg/header.rs index 86661fbc33..aa11982ea1 100644 --- a/components/hab/src/cli_v4/pkg/header.rs +++ b/components/hab/src/cli_v4/pkg/header.rs @@ -20,13 +20,13 @@ use crate::{command::pkg::header, pub(crate) struct PkgHeaderOptions { /// Filepath to the Habitat Package file #[arg(name = "SOURCE", value_parser = FileExistsValueParser)] - source: PathBuf, + source: String, } impl PkgHeaderOptions { pub(super) fn do_header(&self, ui: &mut UI) -> HabResult<()> { crypto::init()?; - header::start(ui, &self.source) + header::start(ui, &PathBuf::from(&self.source)) } } diff --git a/components/hab/src/cli_v4/pkg/install.rs b/components/hab/src/cli_v4/pkg/install.rs index f8b43047c6..89a935b0d2 100644 --- a/components/hab/src/cli_v4/pkg/install.rs +++ b/components/hab/src/cli_v4/pkg/install.rs @@ -63,7 +63,7 @@ pub(crate) struct PkgInstallOptions { #[arg(long = "binlink-dir", default_value = DEFAULT_BINLINK_DIR, env = BINLINK_DIR_ENVVAR, value_parser = NonEmptyStringValueParser::new())] - binlink_dir: PathBuf, + binlink_dir: String, /// Overwrite existing binlinks #[arg(short = 'f', long = "force", action = ArgAction::SetTrue)] @@ -140,9 +140,10 @@ impl PkgInstallOptions { install_hook_mode).await?; if do_binlink { + let binlink_dir = PathBuf::from(&self.binlink_dir); binlink::binlink_all_in_pkg(ui, pkg_install.ident(), - &self.binlink_dir, + &binlink_dir, &FS_ROOT_PATH, self.force)?; }