From 3e05e142b8f16c127dd5df17f94b82c6ebcc7b1b Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Sep 2024 21:37:50 -0700 Subject: [PATCH 01/10] Add user location. --- crates/cli/src/commands/alias.rs | 29 +++++++++++++----------- crates/cli/src/commands/install.rs | 4 +++- crates/cli/src/commands/pin.rs | 26 ++++++++++++--------- crates/cli/src/commands/plugin/add.rs | 25 ++++++++++++-------- crates/cli/src/commands/plugin/remove.rs | 21 ++++++++++++----- crates/cli/src/commands/unalias.rs | 23 ++++++++++++------- crates/cli/src/commands/unpin.rs | 29 +++++++++++++++--------- crates/core/src/flow/setup.rs | 6 ++--- crates/core/src/proto.rs | 20 +++++++++++----- crates/core/src/proto_config.rs | 1 + 10 files changed, 115 insertions(+), 69 deletions(-) diff --git a/crates/cli/src/commands/alias.rs b/crates/cli/src/commands/alias.rs index f886fe652..2fa30a6d9 100644 --- a/crates/cli/src/commands/alias.rs +++ b/crates/cli/src/commands/alias.rs @@ -16,11 +16,11 @@ pub struct AliasArgs { #[arg(required = true, help = "Version or alias to associate with")] spec: UnresolvedVersionSpec, - #[arg( - long, - help = "Add to the global ~/.proto/.prototools instead of local ./.prototools" - )] + #[arg(long, group = "pin", help = "Add to the global ~/.proto/.prototools")] global: bool, + + #[arg(long, group = "pin", help = "Add to the user ~/.prototools")] + user: bool, } #[tracing::instrument(skip_all)] @@ -40,16 +40,19 @@ pub async fn alias(session: ProtoSession, args: AliasArgs) -> AppResult { let tool = session.load_tool(&args.id).await?; - let config_path = ProtoConfig::update(tool.proto.get_config_dir(args.global), |config| { - let tool_configs = config.tools.get_or_insert(Default::default()); + let config_path = ProtoConfig::update( + tool.proto.get_config_dir_from_flags(args.global, args.user), + |config| { + let tool_configs = config.tools.get_or_insert(Default::default()); - tool_configs - .entry(tool.id.clone()) - .or_default() - .aliases - .get_or_insert(Default::default()) - .insert(args.alias.clone(), args.spec.clone()); - })?; + tool_configs + .entry(tool.id.clone()) + .or_default() + .aliases + .get_or_insert(Default::default()) + .insert(args.alias.clone(), args.spec.clone()); + }, + )?; println!( "Added alias {} ({}) to config {}", diff --git a/crates/cli/src/commands/install.rs b/crates/cli/src/commands/install.rs index 29bc44a11..32bbc4566 100644 --- a/crates/cli/src/commands/install.rs +++ b/crates/cli/src/commands/install.rs @@ -23,6 +23,7 @@ use tracing::{debug, instrument}; pub enum PinOption { Global, Local, + User, } #[derive(Args, Clone, Debug, Default)] @@ -62,6 +63,7 @@ impl InstallArgs { fn get_pin_type(&self) -> Option { self.pin.as_ref().map(|pin| match pin { Some(PinOption::Global) => PinType::Global, + Some(PinOption::User) => PinType::User, _ => PinType::Local, }) } @@ -105,7 +107,7 @@ async fn pin_version( } if pin { - internal_pin(tool, &spec, global, true).await?; + internal_pin(tool, &spec, global, false, true).await?; } Ok(pin) diff --git a/crates/cli/src/commands/pin.rs b/crates/cli/src/commands/pin.rs index 779c87504..d8ca03552 100644 --- a/crates/cli/src/commands/pin.rs +++ b/crates/cli/src/commands/pin.rs @@ -15,12 +15,12 @@ pub struct PinArgs { #[arg(required = true, help = "Version or alias of tool")] pub spec: UnresolvedVersionSpec, - #[arg( - long, - help = "Pin to the global ~/.proto/.prototools instead of local ./.prototools" - )] + #[arg(long, group = "pin", help = "Pin to the global ~/.proto/.prototools")] pub global: bool, + #[arg(long, group = "pin", help = "Pin to the user ~/.prototools")] + pub user: bool, + #[arg(long, help = "Resolve the version before pinning")] pub resolve: bool, } @@ -29,6 +29,7 @@ pub async fn internal_pin( tool: &mut Tool, spec: &UnresolvedVersionSpec, global: bool, + user: bool, link: bool, ) -> miette::Result { // Create symlink to this new version @@ -36,12 +37,15 @@ pub async fn internal_pin( tool.symlink_bins(true).await?; } - let config_path = ProtoConfig::update(tool.proto.get_config_dir(global), |config| { - config - .versions - .get_or_insert(BTreeMap::default()) - .insert(tool.id.clone(), spec.clone()); - })?; + let config_path = ProtoConfig::update( + tool.proto.get_config_dir_from_flags(global, user), + |config| { + config + .versions + .get_or_insert(BTreeMap::default()) + .insert(tool.id.clone(), spec.clone()); + }, + )?; debug!( version = spec.to_string(), @@ -63,7 +67,7 @@ pub async fn pin(session: ProtoSession, args: PinArgs) -> AppResult { args.spec.clone() }; - let config_path = internal_pin(&mut tool, &spec, args.global, false).await?; + let config_path = internal_pin(&mut tool, &spec, args.global, args.user, false).await?; println!( "Pinned {} to {} in {}", diff --git a/crates/cli/src/commands/plugin/add.rs b/crates/cli/src/commands/plugin/add.rs index ffbcbb6dc..1946ab93a 100644 --- a/crates/cli/src/commands/plugin/add.rs +++ b/crates/cli/src/commands/plugin/add.rs @@ -12,21 +12,26 @@ pub struct AddPluginArgs { #[arg(required = true, help = "Locator string to find and load the plugin")] plugin: PluginLocator, - #[arg( - long, - help = "Add to the global ~/.proto/.prototools instead of local ./.prototools" - )] + #[arg(long, group = "pin", help = "Add to the global ~/.proto/.prototools")] global: bool, + + #[arg(long, group = "pin", help = "Add to the user ~/.prototools")] + user: bool, } #[tracing::instrument(skip_all)] pub async fn add(session: ProtoSession, args: AddPluginArgs) -> AppResult { - let config_path = ProtoConfig::update(session.env.get_config_dir(args.global), |config| { - config - .plugins - .get_or_insert(Default::default()) - .insert(args.id.clone(), args.plugin.clone()); - })?; + let config_path = ProtoConfig::update( + session + .env + .get_config_dir_from_flags(args.global, args.user), + |config| { + config + .plugins + .get_or_insert(Default::default()) + .insert(args.id.clone(), args.plugin.clone()); + }, + )?; println!( "Added plugin {} to config {}", diff --git a/crates/cli/src/commands/plugin/remove.rs b/crates/cli/src/commands/plugin/remove.rs index 67647a453..313504a26 100644 --- a/crates/cli/src/commands/plugin/remove.rs +++ b/crates/cli/src/commands/plugin/remove.rs @@ -12,9 +12,13 @@ pub struct RemovePluginArgs { #[arg( long, - help = "Remove from the global ~/.proto/.prototools instead of local ./.prototools" + group = "pin", + help = "Remove from the global ~/.proto/.prototools" )] global: bool, + + #[arg(long, group = "pin", help = "Remove from the user ~/.prototools")] + user: bool, } #[tracing::instrument(skip_all)] @@ -27,11 +31,16 @@ pub async fn remove(session: ProtoSession, args: RemovePluginArgs) -> AppResult } } - let config_path = ProtoConfig::update(session.env.get_config_dir(args.global), |config| { - if let Some(plugins) = &mut config.plugins { - plugins.remove(&args.id); - } - })?; + let config_path = ProtoConfig::update( + session + .env + .get_config_dir_from_flags(args.global, args.user), + |config| { + if let Some(plugins) = &mut config.plugins { + plugins.remove(&args.id); + } + }, + )?; println!( "Removed plugin {} from config {}", diff --git a/crates/cli/src/commands/unalias.rs b/crates/cli/src/commands/unalias.rs index 6f7a7a048..9c28a5967 100644 --- a/crates/cli/src/commands/unalias.rs +++ b/crates/cli/src/commands/unalias.rs @@ -15,9 +15,13 @@ pub struct UnaliasArgs { #[arg( long, - help = "Remove from the global ~/.proto/.prototools instead of local ./.prototools" + group = "pin", + help = "Remove from the global ~/.proto/.prototools" )] global: bool, + + #[arg(long, group = "pin", help = "Remove from the user ~/.prototools")] + user: bool, } #[tracing::instrument(skip_all)] @@ -25,15 +29,18 @@ pub async fn unalias(session: ProtoSession, args: UnaliasArgs) -> AppResult { let tool = session.load_tool(&args.id).await?; let mut value = None; - let config_path = ProtoConfig::update(tool.proto.get_config_dir(args.global), |config| { - if let Some(tool_configs) = &mut config.tools { - if let Some(tool_config) = tool_configs.get_mut(&tool.id) { - if let Some(aliases) = &mut tool_config.aliases { - value = aliases.remove(&args.alias); + let config_path = ProtoConfig::update( + tool.proto.get_config_dir_from_flags(args.global, args.user), + |config| { + if let Some(tool_configs) = &mut config.tools { + if let Some(tool_config) = tool_configs.get_mut(&tool.id) { + if let Some(aliases) = &mut tool_config.aliases { + value = aliases.remove(&args.alias); + } } } - } - })?; + }, + )?; let Some(value) = value else { eprintln!( diff --git a/crates/cli/src/commands/unpin.rs b/crates/cli/src/commands/unpin.rs index 15c5c2ab2..f0688f143 100644 --- a/crates/cli/src/commands/unpin.rs +++ b/crates/cli/src/commands/unpin.rs @@ -12,9 +12,13 @@ pub struct UnpinArgs { #[arg( long, - help = "Unpin from the global ~/.proto/.prototools instead of local ./.prototools" + group = "pin", + help = "Unpin from the global ~/.proto/.prototools" )] pub global: bool, + + #[arg(long, group = "pin", help = "Unpin from the user ~/.prototools")] + pub user: bool, } #[tracing::instrument(skip_all)] @@ -22,16 +26,19 @@ pub async fn unpin(session: ProtoSession, args: UnpinArgs) -> AppResult { let tool = session.load_tool(&args.id).await?; let mut value = None; - let config_path = ProtoConfig::update(tool.proto.get_config_dir(args.global), |config| { - if let Some(versions) = &mut config.versions { - value = versions.remove(&tool.id); - } - - // Remove these also just in case - if let Some(versions) = &mut config.unknown { - versions.remove(tool.id.as_str()); - } - })?; + let config_path = ProtoConfig::update( + tool.proto.get_config_dir_from_flags(args.global, args.user), + |config| { + if let Some(versions) = &mut config.versions { + value = versions.remove(&tool.id); + } + + // Remove these also just in case + if let Some(versions) = &mut config.unknown { + versions.remove(tool.id.as_str()); + } + }, + )?; let Some(value) = value else { eprintln!("No version pinned in config {}", color::path(config_path)); diff --git a/crates/core/src/flow/setup.rs b/crates/core/src/flow/setup.rs index f78e92743..f2c79ed79 100644 --- a/crates/core/src/flow/setup.rs +++ b/crates/core/src/flow/setup.rs @@ -1,5 +1,5 @@ use crate::flow::install::InstallOptions; -use crate::proto_config::ProtoConfig; +use crate::proto_config::{PinType, ProtoConfig}; use crate::tool::Tool; use crate::tool_manifest::ToolManifestVersion; use proto_pdk_api::*; @@ -78,7 +78,7 @@ impl Tool { manifest.save()?; // Pin the global version - ProtoConfig::update(self.proto.get_config_dir(true), |config| { + ProtoConfig::update(self.proto.get_config_dir(PinType::Global), |config| { config .versions .get_or_insert(Default::default()) @@ -112,7 +112,7 @@ impl Tool { manifest.save()?; // Unpin global version if a match - ProtoConfig::update(self.proto.get_config_dir(true), |config| { + ProtoConfig::update(self.proto.get_config_dir(PinType::Global), |config| { if let Some(versions) = &mut config.versions { if versions.get(&self.id).is_some_and(|v| v == &version) { debug!("Unpinning global version"); diff --git a/crates/core/src/proto.rs b/crates/core/src/proto.rs index 40c27ca94..277079b18 100644 --- a/crates/core/src/proto.rs +++ b/crates/core/src/proto.rs @@ -2,7 +2,7 @@ use crate::error::ProtoError; use crate::helpers::is_offline; use crate::layout::Store; use crate::proto_config::{ - ConfigMode, ProtoConfig, ProtoConfigFile, ProtoConfigManager, PROTO_CONFIG_NAME, + ConfigMode, PinType, ProtoConfig, ProtoConfigFile, ProtoConfigManager, PROTO_CONFIG_NAME, }; use once_cell::sync::OnceCell; use starbase_utils::dirs::home_dir; @@ -63,11 +63,19 @@ impl ProtoEnvironment { }) } - pub fn get_config_dir(&self, global: bool) -> &Path { - if global { - &self.root - } else { - &self.cwd + pub fn get_config_dir(&self, pin: PinType) -> &Path { + match pin { + PinType::Global => &self.root, + PinType::Local => &self.cwd, + PinType::User => &self.home, + } + } + + pub fn get_config_dir_from_flags(&self, global: bool, user: bool) -> &Path { + match (global, user) { + (true, false) => self.get_config_dir(PinType::Global), + (false, true) => self.get_config_dir(PinType::User), + _ => self.get_config_dir(PinType::Local), } } diff --git a/crates/core/src/proto_config.rs b/crates/core/src/proto_config.rs index dd1ff523a..5c016a3ff 100644 --- a/crates/core/src/proto_config.rs +++ b/crates/core/src/proto_config.rs @@ -124,6 +124,7 @@ derive_enum!( pub enum PinType { Global, Local, + User, } ); From d02a772fa7e720947f16cb9da0ca8853ac4dc019 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Sep 2024 21:43:42 -0700 Subject: [PATCH 02/10] Add aliases. --- CHANGELOG.md | 6 ++++++ crates/cli/src/commands/install.rs | 3 +++ crates/core/src/proto_config.rs | 3 +++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cde867fec..10da81285 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,12 @@ #### 🚀 Updates +- Added support for updating the `~/.prototools` file (root of user home directory). + - Added `--pin=user` to `proto install`. + - Added `--user` to `proto alias`, `unalias`, `pin`, `unpin`, `plugin add`, and `plugin remove`. + - Added `store` as an alias for `global`. + - Added `cwd` as an alias for `local`. + - Added `home` as an alias for `user`. - Added new `settings.offline` settings that control how offline checks work. #### ⚙️ Internal diff --git a/crates/cli/src/commands/install.rs b/crates/cli/src/commands/install.rs index 32bbc4566..83a5d4b3b 100644 --- a/crates/cli/src/commands/install.rs +++ b/crates/cli/src/commands/install.rs @@ -21,8 +21,11 @@ use tracing::{debug, instrument}; #[derive(Clone, Debug, ValueEnum)] pub enum PinOption { + #[value(alias = "store")] Global, + #[value(alias = "cwd")] Local, + #[value(alias = "home")] User, } diff --git a/crates/core/src/proto_config.rs b/crates/core/src/proto_config.rs index 5c016a3ff..b60c50b90 100644 --- a/crates/core/src/proto_config.rs +++ b/crates/core/src/proto_config.rs @@ -122,8 +122,11 @@ derive_enum!( derive_enum!( #[derive(ConfigEnum)] pub enum PinType { + #[serde(alias = "store")] Global, + #[serde(alias = "cwd")] Local, + #[serde(alias = "home")] User, } ); From 156564bfeaa67a74d817615e761fa919a0d2a298 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Sep 2024 21:56:13 -0700 Subject: [PATCH 03/10] Add tests. --- crates/cli/tests/alias_test.rs | 34 ++++++++++++++++++++++++++++++++ crates/cli/tests/pin_test.rs | 24 ++++++++++++++++++++++ crates/cli/tests/unalias_test.rs | 33 +++++++++++++++++++++++++++++++ crates/cli/tests/utils.rs | 2 ++ 4 files changed, 93 insertions(+) diff --git a/crates/cli/tests/alias_test.rs b/crates/cli/tests/alias_test.rs index e9781eb31..e26a64149 100644 --- a/crates/cli/tests/alias_test.rs +++ b/crates/cli/tests/alias_test.rs @@ -146,3 +146,37 @@ mod alias_global { ); } } + +mod alias_user { + use super::*; + + #[test] + fn updates_config_file() { + let sandbox = create_empty_proto_sandbox(); + let config_file = sandbox.path().join(".home/.prototools"); + + assert!(!config_file.exists()); + + sandbox + .run_bin(|cmd| { + cmd.arg("alias") + .arg("node") + .arg("example") + .arg("19.0.0") + .arg("--user"); + }) + .debug(); + + assert!(config_file.exists()); + + let config = load_config(sandbox.path().join(".home")); + + assert_eq!( + config.tools.get("node").unwrap().aliases, + BTreeMap::from_iter([( + "example".into(), + UnresolvedVersionSpec::parse("19.0.0").unwrap() + )]) + ); + } +} diff --git a/crates/cli/tests/pin_test.rs b/crates/cli/tests/pin_test.rs index 69256873a..606152869 100644 --- a/crates/cli/tests/pin_test.rs +++ b/crates/cli/tests/pin_test.rs @@ -253,3 +253,27 @@ mod pin_global { assert!(!link.exists()); } } + +mod pin_user { + use super::*; + + #[test] + fn writes_user_version_file() { + let sandbox = create_empty_proto_sandbox(); + let version_file = sandbox.path().join(".home/.prototools"); + + assert!(!version_file.exists()); + + sandbox + .run_bin(|cmd| { + cmd.arg("pin").arg("node").arg("19.0.0").arg("--user"); + }) + .success(); + + assert!(version_file.exists()); + assert_eq!( + fs::read_to_string(version_file).unwrap(), + "node = \"19.0.0\"\n" + ) + } +} diff --git a/crates/cli/tests/unalias_test.rs b/crates/cli/tests/unalias_test.rs index 010cedb85..f1a8d4515 100644 --- a/crates/cli/tests/unalias_test.rs +++ b/crates/cli/tests/unalias_test.rs @@ -123,3 +123,36 @@ mod unalias_global { assert!(config.tools.get("node").unwrap().aliases.is_empty()); } } + +mod unalias_user { + use super::*; + + #[test] + fn removes_existing_alias() { + let sandbox = create_empty_proto_sandbox(); + + ProtoConfig::update(sandbox.path().join(".home"), |config| { + config.tools.get_or_insert(Default::default()).insert( + Id::raw("node"), + PartialProtoToolConfig { + aliases: Some(BTreeMap::from_iter([( + "example".into(), + UnresolvedVersionSpec::parse("19.0.0").unwrap(), + )])), + ..Default::default() + }, + ); + }) + .unwrap(); + + sandbox + .run_bin(|cmd| { + cmd.arg("unalias").arg("node").arg("example").arg("--user"); + }) + .success(); + + let config = load_config(sandbox.path().join(".home")); + + assert!(config.tools.get("node").unwrap().aliases.is_empty()); + } +} diff --git a/crates/cli/tests/utils.rs b/crates/cli/tests/utils.rs index 5d3eda2d3..11c1add3b 100644 --- a/crates/cli/tests/utils.rs +++ b/crates/cli/tests/utils.rs @@ -30,11 +30,13 @@ impl Deref for ProtoSandbox { fn apply_settings(sandbox: &mut Sandbox) { let proto_dir = sandbox.path().join(".proto"); + let home_dir = sandbox.path().join(".home"); let mut env = HashMap::new(); env.insert("RUST_BACKTRACE", "1"); env.insert("WASMTIME_BACKTRACE_DETAILS", "1"); env.insert("NO_COLOR", "1"); + env.insert("HOME", home_dir.to_str().unwrap()); env.insert("PROTO_HOME", proto_dir.to_str().unwrap()); env.insert("PROTO_LOG", "trace"); env.insert("PROTO_TEST", "true"); From a84c95527a0bd47403b33616f2cc6d9e78590992 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Sep 2024 22:20:42 -0700 Subject: [PATCH 04/10] Use an option instead. --- CHANGELOG.md | 12 +++++---- crates/cli/src/commands/alias.rs | 8 +++--- crates/cli/src/commands/install.rs | 26 ++++++------------ crates/cli/src/commands/pin.rs | 32 +++++++++++----------- crates/cli/src/commands/plugin/add.rs | 7 ++--- crates/cli/src/commands/plugin/remove.rs | 31 ++++++++++----------- crates/cli/src/commands/unalias.rs | 8 +++--- crates/cli/src/commands/unpin.rs | 8 +++--- crates/cli/src/helpers.rs | 29 ++++++++++++++++++++ crates/cli/tests/alias_test.rs | 5 ++-- crates/cli/tests/pin_test.rs | 6 ++++- crates/cli/tests/plugin_add_test.rs | 32 ++++++++++++++++++++++ crates/cli/tests/plugin_remove_test.rs | 34 ++++++++++++++++++++++++ crates/cli/tests/unalias_test.rs | 6 ++++- crates/cli/tests/unpin_test.rs | 27 +++++++++++++++++++ crates/core/src/proto.rs | 8 ------ crates/core/src/proto_config.rs | 2 +- 17 files changed, 199 insertions(+), 82 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10da81285..0278ab7b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,11 +15,13 @@ #### 🚀 Updates - Added support for updating the `~/.prototools` file (root of user home directory). - - Added `--pin=user` to `proto install`. - - Added `--user` to `proto alias`, `unalias`, `pin`, `unpin`, `plugin add`, and `plugin remove`. - - Added `store` as an alias for `global`. - - Added `cwd` as an alias for `local`. - - Added `home` as an alias for `user`. +- Added `--pin=user` to `proto install`. +- Added `--to=global|local|user` to `proto alias`, `pin`, and `plugin add`. +- Added `--from=global|local|user` to `proto unalias`, `unpin`, and `plugin remove`. +- Added aliases for pin locations. + - `cwd` -> `local` + - `home` -> `user` + - `store` -> `global` - Added new `settings.offline` settings that control how offline checks work. #### ⚙️ Internal diff --git a/crates/cli/src/commands/alias.rs b/crates/cli/src/commands/alias.rs index 2fa30a6d9..b1381cf56 100644 --- a/crates/cli/src/commands/alias.rs +++ b/crates/cli/src/commands/alias.rs @@ -1,4 +1,5 @@ use crate::error::ProtoCliError; +use crate::helpers::{map_pin_type, PinOption}; use crate::session::ProtoSession; use clap::Args; use proto_core::{is_alias_name, Id, ProtoConfig, UnresolvedVersionSpec}; @@ -19,8 +20,8 @@ pub struct AliasArgs { #[arg(long, group = "pin", help = "Add to the global ~/.proto/.prototools")] global: bool, - #[arg(long, group = "pin", help = "Add to the user ~/.prototools")] - user: bool, + #[arg(long, group = "pin", help = "Location of .prototools to add to")] + to: Option, } #[tracing::instrument(skip_all)] @@ -41,7 +42,8 @@ pub async fn alias(session: ProtoSession, args: AliasArgs) -> AppResult { let tool = session.load_tool(&args.id).await?; let config_path = ProtoConfig::update( - tool.proto.get_config_dir_from_flags(args.global, args.user), + tool.proto + .get_config_dir(map_pin_type(args.global, args.to)), |config| { let tool_configs = config.tools.get_or_insert(Default::default()); diff --git a/crates/cli/src/commands/install.rs b/crates/cli/src/commands/install.rs index 83a5d4b3b..0dfe152a6 100644 --- a/crates/cli/src/commands/install.rs +++ b/crates/cli/src/commands/install.rs @@ -3,7 +3,7 @@ use crate::helpers::*; use crate::session::ProtoSession; use crate::shell::{self, Export}; use crate::telemetry::{track_usage, Metric}; -use clap::{Args, ValueEnum}; +use clap::Args; use indicatif::ProgressBar; use miette::IntoDiagnostic; use proto_core::flow::install::{InstallOptions, InstallPhase}; @@ -19,16 +19,6 @@ use tokio::task::JoinSet; use tokio::time::sleep; use tracing::{debug, instrument}; -#[derive(Clone, Debug, ValueEnum)] -pub enum PinOption { - #[value(alias = "store")] - Global, - #[value(alias = "cwd")] - Local, - #[value(alias = "home")] - User, -} - #[derive(Args, Clone, Debug, Default)] pub struct InstallArgs { #[arg(help = "ID of a single tool to install")] @@ -87,30 +77,30 @@ async fn pin_version( ) -> miette::Result { let config = tool.proto.load_config()?; let spec = tool.get_resolved_version().to_unresolved_spec(); - let mut global = false; + let mut pin_type = PinType::Local; let mut pin = false; // via `--pin` arg - if let Some(pin_type) = arg_pin_type { - global = matches!(pin_type, PinType::Global); + if let Some(custom_type) = arg_pin_type { + pin_type = *custom_type; pin = true; } // Or the first time being installed else if !config.versions.contains_key(&tool.id) { - global = true; + pin_type = PinType::Global; pin = true; } // via `pin-latest` setting if initial_version.is_latest() { - if let Some(pin_type) = &config.settings.pin_latest { - global = matches!(pin_type, PinType::Global); + if let Some(custom_type) = &config.settings.pin_latest { + pin_type = *custom_type; pin = true; } } if pin { - internal_pin(tool, &spec, global, false, true).await?; + internal_pin(tool, &spec, pin_type, true).await?; } Ok(pin) diff --git a/crates/cli/src/commands/pin.rs b/crates/cli/src/commands/pin.rs index d8ca03552..fc8d96981 100644 --- a/crates/cli/src/commands/pin.rs +++ b/crates/cli/src/commands/pin.rs @@ -1,6 +1,7 @@ +use crate::helpers::{map_pin_type, PinOption}; use crate::session::ProtoSession; use clap::Args; -use proto_core::{Id, ProtoConfig, Tool, UnresolvedVersionSpec}; +use proto_core::{Id, PinType, ProtoConfig, Tool, UnresolvedVersionSpec}; use starbase::AppResult; use starbase_styles::color; use std::collections::BTreeMap; @@ -18,34 +19,30 @@ pub struct PinArgs { #[arg(long, group = "pin", help = "Pin to the global ~/.proto/.prototools")] pub global: bool, - #[arg(long, group = "pin", help = "Pin to the user ~/.prototools")] - pub user: bool, - #[arg(long, help = "Resolve the version before pinning")] pub resolve: bool, + + #[arg(long, group = "pin", help = "Location of .prototools to pin to")] + pub to: Option, } pub async fn internal_pin( tool: &mut Tool, spec: &UnresolvedVersionSpec, - global: bool, - user: bool, + pin: PinType, link: bool, ) -> miette::Result { // Create symlink to this new version - if global && link { + if pin == PinType::Global && link { tool.symlink_bins(true).await?; } - let config_path = ProtoConfig::update( - tool.proto.get_config_dir_from_flags(global, user), - |config| { - config - .versions - .get_or_insert(BTreeMap::default()) - .insert(tool.id.clone(), spec.clone()); - }, - )?; + let config_path = ProtoConfig::update(tool.proto.get_config_dir(pin), |config| { + config + .versions + .get_or_insert(BTreeMap::default()) + .insert(tool.id.clone(), spec.clone()); + })?; debug!( version = spec.to_string(), @@ -67,7 +64,8 @@ pub async fn pin(session: ProtoSession, args: PinArgs) -> AppResult { args.spec.clone() }; - let config_path = internal_pin(&mut tool, &spec, args.global, args.user, false).await?; + let config_path = + internal_pin(&mut tool, &spec, map_pin_type(args.global, args.to), false).await?; println!( "Pinned {} to {} in {}", diff --git a/crates/cli/src/commands/plugin/add.rs b/crates/cli/src/commands/plugin/add.rs index 1946ab93a..6f4d234d4 100644 --- a/crates/cli/src/commands/plugin/add.rs +++ b/crates/cli/src/commands/plugin/add.rs @@ -1,3 +1,4 @@ +use crate::helpers::{map_pin_type, PinOption}; use crate::session::ProtoSession; use clap::Args; use proto_core::{Id, PluginLocator, ProtoConfig}; @@ -15,8 +16,8 @@ pub struct AddPluginArgs { #[arg(long, group = "pin", help = "Add to the global ~/.proto/.prototools")] global: bool, - #[arg(long, group = "pin", help = "Add to the user ~/.prototools")] - user: bool, + #[arg(long, group = "pin", help = "Location of .prototools to add to")] + to: Option, } #[tracing::instrument(skip_all)] @@ -24,7 +25,7 @@ pub async fn add(session: ProtoSession, args: AddPluginArgs) -> AppResult { let config_path = ProtoConfig::update( session .env - .get_config_dir_from_flags(args.global, args.user), + .get_config_dir(map_pin_type(args.global, args.to)), |config| { config .plugins diff --git a/crates/cli/src/commands/plugin/remove.rs b/crates/cli/src/commands/plugin/remove.rs index 313504a26..891221dec 100644 --- a/crates/cli/src/commands/plugin/remove.rs +++ b/crates/cli/src/commands/plugin/remove.rs @@ -1,4 +1,5 @@ use crate::error::ProtoCliError; +use crate::helpers::{map_pin_type, PinOption}; use crate::session::ProtoSession; use clap::Args; use proto_core::{Id, ProtoConfig, PROTO_CONFIG_NAME}; @@ -17,30 +18,26 @@ pub struct RemovePluginArgs { )] global: bool, - #[arg(long, group = "pin", help = "Remove from the user ~/.prototools")] - user: bool, + #[arg(long, group = "pin", help = "Location of .prototools to remove from")] + from: Option, } #[tracing::instrument(skip_all)] pub async fn remove(session: ProtoSession, args: RemovePluginArgs) -> AppResult { - if !args.global { - let config_path = session.env.cwd.join(PROTO_CONFIG_NAME); + let config_dir = session + .env + .get_config_dir(map_pin_type(args.global, args.from)); + let config_path = config_dir.join(PROTO_CONFIG_NAME); - if !config_path.exists() { - return Err(ProtoCliError::MissingToolsConfigInCwd { path: config_path }.into()); - } + if !config_path.exists() { + return Err(ProtoCliError::MissingToolsConfigInCwd { path: config_path }.into()); } - let config_path = ProtoConfig::update( - session - .env - .get_config_dir_from_flags(args.global, args.user), - |config| { - if let Some(plugins) = &mut config.plugins { - plugins.remove(&args.id); - } - }, - )?; + let config_path = ProtoConfig::update(config_dir, |config| { + if let Some(plugins) = &mut config.plugins { + plugins.remove(&args.id); + } + })?; println!( "Removed plugin {} from config {}", diff --git a/crates/cli/src/commands/unalias.rs b/crates/cli/src/commands/unalias.rs index 9c28a5967..2a029ba98 100644 --- a/crates/cli/src/commands/unalias.rs +++ b/crates/cli/src/commands/unalias.rs @@ -1,3 +1,4 @@ +use crate::helpers::{map_pin_type, PinOption}; use crate::session::ProtoSession; use clap::Args; use proto_core::{Id, ProtoConfig}; @@ -20,8 +21,8 @@ pub struct UnaliasArgs { )] global: bool, - #[arg(long, group = "pin", help = "Remove from the user ~/.prototools")] - user: bool, + #[arg(long, group = "pin", help = "Location of .prototools to remove from")] + from: Option, } #[tracing::instrument(skip_all)] @@ -30,7 +31,8 @@ pub async fn unalias(session: ProtoSession, args: UnaliasArgs) -> AppResult { let mut value = None; let config_path = ProtoConfig::update( - tool.proto.get_config_dir_from_flags(args.global, args.user), + tool.proto + .get_config_dir(map_pin_type(args.global, args.from)), |config| { if let Some(tool_configs) = &mut config.tools { if let Some(tool_config) = tool_configs.get_mut(&tool.id) { diff --git a/crates/cli/src/commands/unpin.rs b/crates/cli/src/commands/unpin.rs index f0688f143..be1dbd030 100644 --- a/crates/cli/src/commands/unpin.rs +++ b/crates/cli/src/commands/unpin.rs @@ -1,3 +1,4 @@ +use crate::helpers::{map_pin_type, PinOption}; use crate::session::ProtoSession; use clap::Args; use proto_core::{Id, ProtoConfig}; @@ -17,8 +18,8 @@ pub struct UnpinArgs { )] pub global: bool, - #[arg(long, group = "pin", help = "Unpin from the user ~/.prototools")] - pub user: bool, + #[arg(long, group = "pin", help = "Location of .prototools to unpin from")] + pub from: Option, } #[tracing::instrument(skip_all)] @@ -27,7 +28,8 @@ pub async fn unpin(session: ProtoSession, args: UnpinArgs) -> AppResult { let mut value = None; let config_path = ProtoConfig::update( - tool.proto.get_config_dir_from_flags(args.global, args.user), + tool.proto + .get_config_dir(map_pin_type(args.global, args.from)), |config| { if let Some(versions) = &mut config.versions { value = versions.remove(&tool.id); diff --git a/crates/cli/src/helpers.rs b/crates/cli/src/helpers.rs index 1eb5c0861..e3082d131 100644 --- a/crates/cli/src/helpers.rs +++ b/crates/cli/src/helpers.rs @@ -1,14 +1,43 @@ +use clap::ValueEnum; use dialoguer::{ console::{style, Style}, theme::ColorfulTheme, }; use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; use miette::IntoDiagnostic; +use proto_core::PinType; use starbase_styles::color::{self, Color}; use starbase_utils::env::bool_var; use std::{io::IsTerminal, time::Duration}; use tracing::debug; +#[derive(Clone, Copy, Debug, Default, ValueEnum)] +pub enum PinOption { + #[value(alias = "store")] + Global, + #[default] + #[value(alias = "cwd")] + Local, + #[value(alias = "home")] + User, +} + +pub fn map_pin_type(global: bool, option: Option) -> PinType { + if let Some(option) = option { + return match option { + PinOption::Global => PinType::Global, + PinOption::Local => PinType::Local, + PinOption::User => PinType::User, + }; + } + + if global { + PinType::Global + } else { + PinType::Local + } +} + pub fn create_theme() -> ColorfulTheme { ColorfulTheme { defaults_style: Style::new().for_stderr().color256(Color::Pink as u8), diff --git a/crates/cli/tests/alias_test.rs b/crates/cli/tests/alias_test.rs index e26a64149..602522980 100644 --- a/crates/cli/tests/alias_test.rs +++ b/crates/cli/tests/alias_test.rs @@ -163,9 +163,10 @@ mod alias_user { .arg("node") .arg("example") .arg("19.0.0") - .arg("--user"); + .arg("--to") + .arg("user"); }) - .debug(); + .success(); assert!(config_file.exists()); diff --git a/crates/cli/tests/pin_test.rs b/crates/cli/tests/pin_test.rs index 606152869..71ce40ca6 100644 --- a/crates/cli/tests/pin_test.rs +++ b/crates/cli/tests/pin_test.rs @@ -266,7 +266,11 @@ mod pin_user { sandbox .run_bin(|cmd| { - cmd.arg("pin").arg("node").arg("19.0.0").arg("--user"); + cmd.arg("pin") + .arg("node") + .arg("19.0.0") + .arg("--to") + .arg("home"); }) .success(); diff --git a/crates/cli/tests/plugin_add_test.rs b/crates/cli/tests/plugin_add_test.rs index 2580a9f2e..c12fbb254 100644 --- a/crates/cli/tests/plugin_add_test.rs +++ b/crates/cli/tests/plugin_add_test.rs @@ -83,4 +83,36 @@ mod plugin_add { })) ); } + + #[test] + fn updates_user_file() { + let sandbox = create_empty_proto_sandbox(); + let config_file = sandbox.path().join(".home/.prototools"); + + assert!(!config_file.exists()); + + sandbox + .run_bin(|cmd| { + cmd.arg("plugin") + .arg("add") + .arg("id") + .arg("https://github.com/moonrepo/tools/releases/latest/download/example_plugin.wasm") + .arg("--to") + .arg("user"); + }) + .success(); + + assert!(config_file.exists()); + + let config = load_config(sandbox.path().join(".home")); + + assert_eq!( + config.plugins.get("id").unwrap(), + &PluginLocator::Url(Box::new(UrlLocator { + url: + "https://github.com/moonrepo/tools/releases/latest/download/example_plugin.wasm" + .into() + })) + ); + } } diff --git a/crates/cli/tests/plugin_remove_test.rs b/crates/cli/tests/plugin_remove_test.rs index 1cadc235e..64af64797 100644 --- a/crates/cli/tests/plugin_remove_test.rs +++ b/crates/cli/tests/plugin_remove_test.rs @@ -75,4 +75,38 @@ mod plugin_remove { assert!(!config.plugins.contains_key("id")); } + + #[test] + fn updates_user_file() { + let sandbox = create_empty_proto_sandbox(); + + ProtoConfig::update(sandbox.path().join(".home"), |config| { + config + .plugins + .get_or_insert(Default::default()) + .insert( + Id::raw("id"), + PluginLocator::Url(Box::new(UrlLocator { + url: "https://github.com/moonrepo/tools/releases/latest/download/example_plugin.wasm".into() + })), + ); + }) + .unwrap(); + + sandbox.debug_files(); + + sandbox + .run_bin(|cmd| { + cmd.arg("plugin") + .arg("remove") + .arg("id") + .arg("--from") + .arg("user"); + }) + .success(); + + let config = load_config(sandbox.path().join(".home")); + + assert!(!config.plugins.contains_key("id")); + } } diff --git a/crates/cli/tests/unalias_test.rs b/crates/cli/tests/unalias_test.rs index f1a8d4515..bb435c19f 100644 --- a/crates/cli/tests/unalias_test.rs +++ b/crates/cli/tests/unalias_test.rs @@ -147,7 +147,11 @@ mod unalias_user { sandbox .run_bin(|cmd| { - cmd.arg("unalias").arg("node").arg("example").arg("--user"); + cmd.arg("unalias") + .arg("node") + .arg("example") + .arg("--from") + .arg("user"); }) .success(); diff --git a/crates/cli/tests/unpin_test.rs b/crates/cli/tests/unpin_test.rs index 2e731f445..7cc7b3ea8 100644 --- a/crates/cli/tests/unpin_test.rs +++ b/crates/cli/tests/unpin_test.rs @@ -97,3 +97,30 @@ mod unpin_global { assert!(!config.versions.contains_key("node")); } } + +mod unpin_user { + use super::*; + + #[test] + fn removes_existing_pin() { + let sandbox = create_empty_proto_sandbox(); + + ProtoConfig::update(sandbox.path().join(".home"), |config| { + config + .versions + .get_or_insert(Default::default()) + .insert(Id::raw("node"), UnresolvedVersionSpec::Canary); + }) + .unwrap(); + + sandbox + .run_bin(|cmd| { + cmd.arg("unpin").arg("node").arg("--from").arg("user"); + }) + .success(); + + let config = load_config(sandbox.path().join(".home")); + + assert!(!config.versions.contains_key("node")); + } +} diff --git a/crates/core/src/proto.rs b/crates/core/src/proto.rs index 277079b18..772271e75 100644 --- a/crates/core/src/proto.rs +++ b/crates/core/src/proto.rs @@ -71,14 +71,6 @@ impl ProtoEnvironment { } } - pub fn get_config_dir_from_flags(&self, global: bool, user: bool) -> &Path { - match (global, user) { - (true, false) => self.get_config_dir(PinType::Global), - (false, true) => self.get_config_dir(PinType::User), - _ => self.get_config_dir(PinType::Local), - } - } - pub fn get_plugin_loader(&self) -> miette::Result<&PluginLoader> { let config = self.load_config()?; diff --git a/crates/core/src/proto_config.rs b/crates/core/src/proto_config.rs index b60c50b90..446f27fe5 100644 --- a/crates/core/src/proto_config.rs +++ b/crates/core/src/proto_config.rs @@ -120,7 +120,7 @@ derive_enum!( ); derive_enum!( - #[derive(ConfigEnum)] + #[derive(Copy, ConfigEnum)] pub enum PinType { #[serde(alias = "store")] Global, From 2d048b0901b9f69a16dffbbb22bfbccdf255d353 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Sep 2024 22:51:24 -0700 Subject: [PATCH 05/10] Try and fix tests. --- crates/cli/src/systems.rs | 10 ++++++++++ crates/cli/tests/unalias_test.rs | 4 +--- crates/cli/tests/utils.rs | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/cli/src/systems.rs b/crates/cli/src/systems.rs index bee7c2843..85bf9559b 100644 --- a/crates/cli/src/systems.rs +++ b/crates/cli/src/systems.rs @@ -20,6 +20,16 @@ use tracing::{debug, instrument}; #[instrument(skip_all)] pub fn detect_proto_env(cli: &CLI) -> AppResult { + #[cfg(test)] + let mut env = { + let sandbox = env::var("PROTO_SANDBOX") + .map(|value| std::path::PathBuf::from(&value)) + .expect("Missing sandbox root for testing!"); + + ProtoEnvironment::new_testing(&sandbox)? + }; + + #[cfg(not(test))] let mut env = ProtoEnvironment::new()?; env.config_mode = cli.config_mode.unwrap_or(match cli.command { diff --git a/crates/cli/tests/unalias_test.rs b/crates/cli/tests/unalias_test.rs index bb435c19f..25b2e5ad2 100644 --- a/crates/cli/tests/unalias_test.rs +++ b/crates/cli/tests/unalias_test.rs @@ -39,13 +39,11 @@ mod unalias_local { }) .unwrap(); - sandbox.debug_files(); - sandbox .run_bin(|cmd| { cmd.arg("unalias").arg("node").arg("example"); }) - .debug(); + .success(); let config = load_config(sandbox.path()); diff --git a/crates/cli/tests/utils.rs b/crates/cli/tests/utils.rs index 11c1add3b..46e0de621 100644 --- a/crates/cli/tests/utils.rs +++ b/crates/cli/tests/utils.rs @@ -29,6 +29,7 @@ impl Deref for ProtoSandbox { } fn apply_settings(sandbox: &mut Sandbox) { + let root = sandbox.path().to_path_buf(); let proto_dir = sandbox.path().join(".proto"); let home_dir = sandbox.path().join(".home"); @@ -37,6 +38,7 @@ fn apply_settings(sandbox: &mut Sandbox) { env.insert("WASMTIME_BACKTRACE_DETAILS", "1"); env.insert("NO_COLOR", "1"); env.insert("HOME", home_dir.to_str().unwrap()); + env.insert("PROTO_SANDBOX", root.to_str().unwrap()); env.insert("PROTO_HOME", proto_dir.to_str().unwrap()); env.insert("PROTO_LOG", "trace"); env.insert("PROTO_TEST", "true"); From fd6698d7143d38ef208ec5bc2430370fca39fe7a Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Sep 2024 23:11:12 -0700 Subject: [PATCH 06/10] Try and fix tests. --- crates/cli/src/systems.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/cli/src/systems.rs b/crates/cli/src/systems.rs index 85bf9559b..0bdfaa21f 100644 --- a/crates/cli/src/systems.rs +++ b/crates/cli/src/systems.rs @@ -20,18 +20,12 @@ use tracing::{debug, instrument}; #[instrument(skip_all)] pub fn detect_proto_env(cli: &CLI) -> AppResult { - #[cfg(test)] - let mut env = { - let sandbox = env::var("PROTO_SANDBOX") - .map(|value| std::path::PathBuf::from(&value)) - .expect("Missing sandbox root for testing!"); - - ProtoEnvironment::new_testing(&sandbox)? + let mut env = if let Ok(sandbox) = env::var("PROTO_SANDBOX") { + ProtoEnvironment::new_testing(&std::path::PathBuf::from(&sandbox))? + } else { + ProtoEnvironment::new()? }; - #[cfg(not(test))] - let mut env = ProtoEnvironment::new()?; - env.config_mode = cli.config_mode.unwrap_or(match cli.command { Commands::Activate(_) | Commands::Install(_) From f0a97bc7ed9d10358d70668a42db0c00e9577d0f Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Sep 2024 23:31:11 -0700 Subject: [PATCH 07/10] Change home handling. --- crates/cli/src/systems.rs | 4 ++++ crates/cli/tests/utils.rs | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/cli/src/systems.rs b/crates/cli/src/systems.rs index 0bdfaa21f..b612d623d 100644 --- a/crates/cli/src/systems.rs +++ b/crates/cli/src/systems.rs @@ -20,12 +20,16 @@ use tracing::{debug, instrument}; #[instrument(skip_all)] pub fn detect_proto_env(cli: &CLI) -> AppResult { + #[cfg(debug_assertions)] let mut env = if let Ok(sandbox) = env::var("PROTO_SANDBOX") { ProtoEnvironment::new_testing(&std::path::PathBuf::from(&sandbox))? } else { ProtoEnvironment::new()? }; + #[cfg(not(debug_assertions))] + let mut env = ProtoEnvironment::new()?; + env.config_mode = cli.config_mode.unwrap_or(match cli.command { Commands::Activate(_) | Commands::Install(_) diff --git a/crates/cli/tests/utils.rs b/crates/cli/tests/utils.rs index 46e0de621..389bf8823 100644 --- a/crates/cli/tests/utils.rs +++ b/crates/cli/tests/utils.rs @@ -31,13 +31,11 @@ impl Deref for ProtoSandbox { fn apply_settings(sandbox: &mut Sandbox) { let root = sandbox.path().to_path_buf(); let proto_dir = sandbox.path().join(".proto"); - let home_dir = sandbox.path().join(".home"); let mut env = HashMap::new(); env.insert("RUST_BACKTRACE", "1"); env.insert("WASMTIME_BACKTRACE_DETAILS", "1"); env.insert("NO_COLOR", "1"); - env.insert("HOME", home_dir.to_str().unwrap()); env.insert("PROTO_SANDBOX", root.to_str().unwrap()); env.insert("PROTO_HOME", proto_dir.to_str().unwrap()); env.insert("PROTO_LOG", "trace"); From de1ef2950b1b3525a752d2bdcf668c3f2fae523b Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 6 Sep 2024 10:09:39 -0700 Subject: [PATCH 08/10] Update utils. --- crates/cli/tests/utils.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/cli/tests/utils.rs b/crates/cli/tests/utils.rs index 389bf8823..7ccb83a26 100644 --- a/crates/cli/tests/utils.rs +++ b/crates/cli/tests/utils.rs @@ -30,8 +30,13 @@ impl Deref for ProtoSandbox { fn apply_settings(sandbox: &mut Sandbox) { let root = sandbox.path().to_path_buf(); + let home_dir = sandbox.path().join(".home"); let proto_dir = sandbox.path().join(".proto"); + // Folders must exist or tests fail! + fs::create_dir_all(&home_dir).unwrap(); + fs::create_dir_all(&proto_dir).unwrap(); + let mut env = HashMap::new(); env.insert("RUST_BACKTRACE", "1"); env.insert("WASMTIME_BACKTRACE_DETAILS", "1"); From 0ac16c2c2d0e1576d6a93360c1ae16dcbf7b5d5b Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 6 Sep 2024 15:12:28 -0700 Subject: [PATCH 09/10] More fixes. --- crates/cli/src/systems.rs | 1 + crates/core/src/proto.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/cli/src/systems.rs b/crates/cli/src/systems.rs index b612d623d..8f6dd30b6 100644 --- a/crates/cli/src/systems.rs +++ b/crates/cli/src/systems.rs @@ -46,6 +46,7 @@ pub fn detect_proto_env(cli: &CLI) -> AppResult { #[instrument(skip_all)] pub fn load_proto_configs(env: &ProtoEnvironment) -> AppResult { debug!( + working_dir = ?env.cwd, "Loading configuration in {} mode", env.config_mode.to_string() ); diff --git a/crates/core/src/proto.rs b/crates/core/src/proto.rs index 772271e75..357721423 100644 --- a/crates/core/src/proto.rs +++ b/crates/core/src/proto.rs @@ -39,7 +39,6 @@ impl ProtoEnvironment { pub fn new_testing(sandbox: &Path) -> miette::Result { let mut env = Self::from(sandbox.join(".proto"), sandbox.join(".home"))?; - env.cwd = sandbox.to_path_buf(); env.test_only = true; Ok(env) @@ -47,14 +46,19 @@ impl ProtoEnvironment { pub fn from, H: AsRef>(root: R, home: H) -> miette::Result { let root = root.as_ref(); + let home = home.as_ref(); - debug!(store = ?root, "Creating proto environment, detecting store"); + debug!( + store = ?root, + home = ?home, + "Creating proto environment, detecting store", + ); Ok(ProtoEnvironment { config_mode: ConfigMode::Upwards, cwd: env::current_dir().expect("Unable to determine current working directory!"), env_mode: env::var("PROTO_ENV").ok(), - home: home.as_ref().to_owned(), + home: home.to_owned(), root: root.to_owned(), config_manager: Arc::new(OnceCell::new()), plugin_loader: Arc::new(OnceCell::new()), From 307391a0c411c60cb0fac347c74f7e767732bdfd Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 6 Sep 2024 15:33:35 -0700 Subject: [PATCH 10/10] Disable cache. --- .github/workflows/ci.yml | 8 +++++--- CHANGELOG.md | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c32935f57..ad9b8909b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,8 +66,9 @@ jobs: - uses: moonrepo/setup-rust@v1 with: bins: cargo-wasi, cargo-nextest, just - cache: ${{ runner.os != 'Linux' }} - cache-base: "^(master|develop-)" + cache: false + # cache: ${{ runner.os != 'Linux' }} + # cache-base: "^(master|develop-)" - if: ${{ runner.os != 'Windows' }} run: just build-wasm env: @@ -95,7 +96,8 @@ jobs: - uses: moonrepo/setup-rust@v1 with: bins: cargo-wasi, just - cache-base: "^(master|develop-)" + cache: false + # cache-base: "^(master|develop-)" - run: just build - run: just build-wasm - run: cargo run -- --help diff --git a/CHANGELOG.md b/CHANGELOG.md index 0278ab7b5..d5e913560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - `home` -> `user` - `store` -> `global` - Added new `settings.offline` settings that control how offline checks work. +- Deprecated the `--global` flag. #### ⚙️ Internal