-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added `hab pkg install` - Added `hab pkg uninstall` Signed-off-by: Abhijit Gadgil <[email protected]>
- Loading branch information
1 parent
ec5ae9f
commit d4f79d7
Showing
13 changed files
with
274 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Implementation of `hab pkg install` command | ||
|
||
use clap_v4 as clap; | ||
|
||
use std::path::PathBuf; | ||
|
||
use clap::{parser::ValueSource, | ||
ArgAction, | ||
CommandFactory, | ||
Parser}; | ||
|
||
use habitat_core::{env::Config, | ||
fs::{cache_artifact_path, | ||
FS_ROOT_PATH}, | ||
ChannelIdent}; | ||
|
||
use habitat_common::{cli::{BINLINK_DIR_ENVVAR, | ||
DEFAULT_BINLINK_DIR}, | ||
command::package::install::{self, | ||
InstallHookMode, | ||
InstallMode, | ||
InstallSource, | ||
LocalPackageUsage}, | ||
ui::UI, | ||
FeatureFlag, | ||
FEATURE_FLAGS}; | ||
|
||
use crate::{command::pkg::binlink, | ||
error::Result as HabResult, | ||
PRODUCT, | ||
VERSION}; | ||
|
||
use crate::cli_v4::utils::{AuthToken, | ||
BldrUrl}; | ||
|
||
#[derive(Debug, Clone, Parser)] | ||
#[command(arg_required_else_help = true, rename_all = "screaming_snake")] | ||
pub(crate) struct PkgInstallOptions { | ||
#[command(flatten)] | ||
bldr_url: BldrUrl, | ||
|
||
/// Install from the specified release channel | ||
#[arg(short = 'c', | ||
long = "channel", | ||
default_value = "stable", | ||
env = ChannelIdent::ENVVAR)] | ||
channel: ChannelIdent, | ||
|
||
/// One or more Habitat package identifiers (ex: acme/redis) and/or filepaths to a Habitat | ||
/// Artifact (ex: /home/acme-redis-3.0.7-21120102031201-x86_64-linux.hart) | ||
#[arg(required = true)] | ||
pkg_ident_or_artifact: Vec<InstallSource>, | ||
|
||
/// Binlink all binaries from installed package(s) into BINLINK_DIR | ||
#[arg(short = 'b', long = "binlink")] | ||
binlink: bool, | ||
|
||
/// Binlink all binaries from installed package(s) into BINLINK_DIR | ||
#[arg(long = "binlink-dir", | ||
default_value = DEFAULT_BINLINK_DIR, | ||
env = BINLINK_DIR_ENVVAR)] | ||
binlink_dir: PathBuf, | ||
|
||
/// Overwrite existing binlinks | ||
#[arg(short = 'f', long = "force", action = ArgAction::SetTrue)] | ||
force: bool, | ||
|
||
#[command(flatten)] | ||
auth_token: AuthToken, | ||
|
||
/// Do not run any install hooks | ||
#[arg(long = "ignore-install-hook", action = ArgAction::SetTrue)] | ||
ignore_install_hook: bool, | ||
|
||
/// Install packages in offline mode | ||
#[arg(long = "offline", | ||
action = ArgAction::SetTrue, | ||
hide = !FEATURE_FLAGS.contains(FeatureFlag::OFFLINE_INSTALL))] | ||
offline: bool, | ||
|
||
/// Do not use locally-installed packages when a corresponding package cannot be installed | ||
/// from Builder | ||
#[arg(long = "ignore-local", | ||
action = ArgAction::SetTrue, | ||
hide = !FEATURE_FLAGS.contains(FeatureFlag::IGNORE_LOCAL))] | ||
ignore_local: bool, | ||
} | ||
|
||
impl PkgInstallOptions { | ||
pub(crate) async fn do_install(&self, | ||
ui: &mut UI, | ||
feature_flags: FeatureFlag) | ||
-> HabResult<()> { | ||
let pkg_install_args: Vec<_> = std::env::args_os().skip(2).collect(); | ||
|
||
let auth_token = self.auth_token.try_from_cli_or_config(); | ||
|
||
let install_mode = if feature_flags.contains(FeatureFlag::OFFLINE_INSTALL) && self.offline { | ||
InstallMode::Offline | ||
} else { | ||
InstallMode::default() | ||
}; | ||
|
||
let local_package_usage = | ||
if feature_flags.contains(FeatureFlag::IGNORE_LOCAL) && self.ignore_local { | ||
LocalPackageUsage::Ignore | ||
} else { | ||
LocalPackageUsage::default() | ||
}; | ||
|
||
let install_hook_mode = if !self.ignore_install_hook { | ||
InstallHookMode::Ignore | ||
} else { | ||
InstallHookMode::default() | ||
}; | ||
|
||
let matches = Self::command().get_matches_from(pkg_install_args); | ||
let do_binlink = match matches.value_source("binlink_dir") { | ||
Some(ValueSource::CommandLine) => true, | ||
_ => self.binlink, | ||
}; | ||
|
||
for install_source in &self.pkg_ident_or_artifact { | ||
// let install_source = InstallSource::from_str(install_source)?; | ||
let pkg_install = install::start(ui, | ||
&self.bldr_url.to_string(), | ||
&self.channel, | ||
&install_source, | ||
PRODUCT, | ||
VERSION, | ||
&FS_ROOT_PATH, | ||
&cache_artifact_path(Some(FS_ROOT_PATH.as_path())), | ||
auth_token.as_deref(), | ||
&install_mode, | ||
&local_package_usage, | ||
install_hook_mode).await?; | ||
|
||
if do_binlink { | ||
binlink::binlink_all_in_pkg(ui, | ||
pkg_install.ident(), | ||
&self.binlink_dir, | ||
&FS_ROOT_PATH, | ||
self.force)?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Implementation of `hab pkg uninstall` command | ||
use clap_v4 as clap; | ||
|
||
use clap::{ArgAction, | ||
Parser}; | ||
|
||
use habitat_core::{fs::FS_ROOT_PATH, | ||
package::PackageIdent}; | ||
|
||
use habitat_common::ui::UI; | ||
|
||
use crate::{command::pkg::{uninstall, | ||
uninstall::UninstallHookMode, | ||
ExecutionStrategy, | ||
Scope}, | ||
error::Result as HabResult}; | ||
|
||
#[derive(Debug, Clone, Parser)] | ||
#[command(arg_required_else_help = true)] | ||
pub(crate) struct PkgUninstallOptions { | ||
#[arg(name = "PKG_IDENT")] | ||
pkg_ident: PackageIdent, | ||
|
||
/// Just show what would be uninstalled, don't actually do it | ||
#[arg(name = "DRYRUN", short = 'd', long = "dryrun", action = ArgAction::SetTrue)] | ||
dryrun: bool, | ||
|
||
/// Only keep this number of latest packages uninstalling all others. | ||
#[arg(name = "KEEP_LATEST", long = "keep-latest")] | ||
keep_latest: Option<usize>, | ||
|
||
/// Identifier of one or more packages that should not be uninstalled. (ex: core/redis, | ||
/// core/busybox-static/1.42.2/21120102031201) | ||
#[arg(name = "EXCLUDE", long = "exclude")] | ||
exclude: Vec<PackageIdent>, | ||
|
||
/// Don't uninstall dependencies | ||
#[arg(name = "NO_DEPS", long = "no-deps")] | ||
no_deps: bool, | ||
|
||
/// Do not run any uninstall hooks | ||
#[arg(name = "IGNORE_UNINSTALL_HOOK", long = "ignore-uninstall-hook")] | ||
ignore_uninstall_hook: bool, | ||
} | ||
|
||
impl PkgUninstallOptions { | ||
pub(crate) async fn do_uninstall(&self, ui: &mut UI) -> HabResult<()> { | ||
let exec_strategy = if self.dryrun { | ||
ExecutionStrategy::DryRun | ||
} else { | ||
ExecutionStrategy::Run | ||
}; | ||
|
||
let uninstall_mode = self.keep_latest.into(); | ||
|
||
let scope = if self.no_deps { | ||
Scope::Package | ||
} else { | ||
Scope::PackageAndDependencies | ||
}; | ||
|
||
let uninstall_hook_mode = if self.ignore_uninstall_hook { | ||
UninstallHookMode::Ignore | ||
} else { | ||
UninstallHookMode::default() | ||
}; | ||
|
||
uninstall::start(ui, | ||
&self.pkg_ident, | ||
&FS_ROOT_PATH, | ||
exec_strategy, | ||
uninstall_mode, | ||
scope, | ||
&self.exclude, | ||
uninstall_hook_mode).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.