use crate::commands;
use clap::Args;
#[derive(Args, Debug, Default, Clone, Copy)]
#[command(next_help_heading = "Lockfile")]
pub(crate) struct LockfileArgs {
#[arg(long, conflicts_with_all = ["no_frozen_lockfile", "prefer_frozen_lockfile"])]
pub frozen_lockfile: bool,
#[arg(long, conflicts_with_all = ["frozen_lockfile", "prefer_frozen_lockfile"])]
pub no_frozen_lockfile: bool,
#[arg(long, conflicts_with_all = ["frozen_lockfile", "no_frozen_lockfile"])]
pub prefer_frozen_lockfile: bool,
}
impl LockfileArgs {
pub fn frozen_override(&self) -> Option<commands::install::FrozenOverride> {
if self.frozen_lockfile {
Some(commands::install::FrozenOverride::Frozen)
} else if self.no_frozen_lockfile {
Some(commands::install::FrozenOverride::No)
} else if self.prefer_frozen_lockfile {
Some(commands::install::FrozenOverride::Prefer)
} else {
None
}
}
pub fn install_overrides(&self) {
commands::set_global_frozen_override(self.frozen_override());
}
}
#[derive(Args, Debug, Default, Clone)]
#[command(next_help_heading = "Network")]
pub(crate) struct NetworkArgs {
#[arg(long, value_name = "N")]
pub fetch_retries: Option<u64>,
#[arg(long, value_name = "N")]
pub fetch_retry_factor: Option<u64>,
#[arg(long, value_name = "MS")]
pub fetch_retry_maxtimeout: Option<u64>,
#[arg(long, value_name = "MS")]
pub fetch_retry_mintimeout: Option<u64>,
#[arg(long, value_name = "MS")]
pub fetch_timeout: Option<u64>,
#[arg(long, value_name = "URL")]
pub registry: Option<String>,
}
impl NetworkArgs {
pub fn fetch_cli_flag_bag(&self) -> Vec<(String, String)> {
let mut out = Vec::new();
if let Some(v) = self.fetch_timeout {
out.push(("fetch-timeout".to_string(), v.to_string()));
}
if let Some(v) = self.fetch_retries {
out.push(("fetch-retries".to_string(), v.to_string()));
}
if let Some(v) = self.fetch_retry_factor {
out.push(("fetch-retry-factor".to_string(), v.to_string()));
}
if let Some(v) = self.fetch_retry_mintimeout {
out.push(("fetch-retry-mintimeout".to_string(), v.to_string()));
}
if let Some(v) = self.fetch_retry_maxtimeout {
out.push(("fetch-retry-maxtimeout".to_string(), v.to_string()));
}
out
}
pub fn install_overrides(&self) {
commands::set_registry_override(self.registry.clone());
commands::set_fetch_cli_overrides(self.fetch_cli_flag_bag());
}
}
#[derive(Args, Debug, Default, Clone, Copy)]
#[command(next_help_heading = "Virtual store")]
pub(crate) struct VirtualStoreArgs {
#[arg(
long,
visible_alias = "disable-gvs",
conflicts_with = "enable_global_virtual_store"
)]
pub disable_global_virtual_store: bool,
#[arg(
long,
visible_alias = "enable-gvs",
conflicts_with = "disable_global_virtual_store"
)]
pub enable_global_virtual_store: bool,
}
impl VirtualStoreArgs {
pub fn flags(&self) -> commands::install::GlobalVirtualStoreFlags {
commands::install::GlobalVirtualStoreFlags {
enable: self.enable_global_virtual_store,
disable: self.disable_global_virtual_store,
}
}
pub fn install_overrides(&self) {
commands::set_global_virtual_store_flags(self.flags());
}
}