Skip to content

Commit

Permalink
Fixes to issues found during testing - pass 1
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijit Gadgil <[email protected]>
  • Loading branch information
agadgil-progress committed Aug 26, 2024
1 parent ac1f582 commit bd42815
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
3 changes: 1 addition & 2 deletions components/common/src/cli/clap_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion components/hab/src/cli_v4/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
45 changes: 38 additions & 7 deletions components/hab/src/cli_v4/pkg/export.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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"))]
Expand All @@ -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::<Vec<_>>()).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::<Vec<_>>()).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::<Vec<_>>()).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::<Vec<_>>()).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::<Vec<_>>()).await
}
}
}
}
4 changes: 2 additions & 2 deletions components/hab/src/cli_v4/pkg/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
5 changes: 3 additions & 2 deletions components/hab/src/cli_v4/pkg/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)?;
}
Expand Down

0 comments on commit bd42815

Please sign in to comment.