use anyhow::Result;
use crate::application::cli::arguments::{Cli, Commands, ConfigAction, HooksAction, PackageAction};
use crate::application::features;
use crate::services::storage::lock_storage::LockStorage;
use crate::utils::static_paths::UpstreamPaths;
impl Cli {
pub async fn run(self) -> Result<()> {
let command = self.command;
let paths = UpstreamPaths::new()?;
let _lock = if command.requires_lock() {
Some(LockStorage::acquire(&paths, &command)?)
} else {
None
};
match command {
Commands::Hooks { action } => match action {
HooksAction::Init => features::hooks::run_hooks_init(),
HooksAction::Check => features::hooks::run_hooks_check(),
HooksAction::Clean => features::hooks::run_hooks_clean(),
HooksAction::Purge { yes } => features::hooks::run_hooks_purge(yes),
},
Commands::Install {
name,
repo_slug,
kind,
tag,
provider,
base_url,
channel,
match_pattern,
exclude_pattern,
desktop,
ignore_checksums,
yes,
} => {
features::install::run(
name,
repo_slug,
kind,
tag,
provider,
base_url,
channel,
match_pattern,
exclude_pattern,
desktop,
ignore_checksums,
yes,
)
.await
}
Commands::Build {
name,
repo_slug,
tag,
provider,
base_url,
channel,
match_pattern,
exclude_pattern,
desktop,
yes,
build_profile,
build_output,
} => {
features::build::run(
name,
repo_slug,
tag,
provider,
base_url,
channel,
match_pattern,
exclude_pattern,
desktop,
yes,
build_profile,
build_output,
)
.await
}
Commands::Remove {
names,
purge: purge_option,
} => features::remove::run(names, purge_option),
Commands::Reinstall {
names,
ignore_checksums,
} => features::reinstall::run(names, ignore_checksums).await,
Commands::Upgrade {
names,
force,
check,
machine_readable,
ignore_checksums,
} => {
features::upgrade::run(names, force, check, machine_readable, ignore_checksums)
.await
}
Commands::List { name } => features::list::run(name),
Commands::Probe {
repo_slug,
provider,
base_url,
channel,
limit,
verbose,
} => features::probe::run(repo_slug, provider, base_url, channel, limit, verbose).await,
Commands::Config { action } => match action {
ConfigAction::Set { keys } => features::config::run_set(keys),
ConfigAction::Get { keys } => features::config::run_get(keys),
ConfigAction::List => features::config::run_list(),
ConfigAction::Edit => features::config::run_edit(),
ConfigAction::Reset => features::config::run_reset(),
},
Commands::Package { action } => match action {
PackageAction::Pin { name } => features::package::run_pin(name),
PackageAction::Unpin { name } => features::package::run_unpin(name),
PackageAction::Remove { name } => features::package::run_remove(name),
PackageAction::SetKey { name, keys } => features::package::run_set_key(name, keys),
PackageAction::Rename { old_name, new_name } => {
features::package::run_rename(old_name, new_name)
}
PackageAction::GetKey { name, keys } => features::package::run_get_key(name, keys),
PackageAction::Metadata { name } => features::package::run_metadata(name),
},
Commands::Export { path, full } => features::export::run_export(path, full).await,
Commands::Import { path, skip_failed } => {
features::import::run_import(path, skip_failed).await
}
Commands::Doctor { names, verbose } => features::doctor::run(names, verbose),
}
}
}