Skip to content

Commit

Permalink
Add closets.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 29, 2023
1 parent 1ddd96a commit 40407b7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#### 🚀 Updates

- Added a `proto outdated` command that'll check for new versions of configured tools.
- Added a `proto pin` command, which is a merge of the old `proto global` and `proto local` commands.
- Added a `pin-latest` setting to `~/.proto/config.toml` that'll automatically pin tools when they're being installed with the "latest" version.
- Updated `proto install` to auto-clean stale plugins after a successful installation.
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/commands/outdated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ pub struct OutdatedArgs {

#[arg(
long,
help = "Check for latest version available ignoring requirements and ranges"
help = "Check for latest available version ignoring requirements and ranges"
)]
latest: bool,

#[arg(long, help = "Update the versions in the local configuration")]
#[arg(long, help = "Update and write the versions to the local .prototools")]
update: bool,
}

Expand All @@ -34,7 +34,7 @@ pub struct OutdatedItem {

#[system]
pub async fn outdated(args: ArgsRef<OutdatedArgs>) {
let mut tools_config = ToolsConfig::load()?;
let mut tools_config = ToolsConfig::load_closest()?;
let initial_version = UnresolvedVersionSpec::default(); // latest

if tools_config.tools.is_empty() {
Expand Down
16 changes: 13 additions & 3 deletions crates/core/src/tools_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,23 @@ impl ToolsConfig {
Ok(config)
}

pub fn load_closest() -> miette::Result<Self> {
let working_dir = env::current_dir().expect("Unknown current working directory!");

Self::load_upwards_from(working_dir, true)
}

pub fn load_upwards() -> miette::Result<Self> {
let working_dir = env::current_dir().expect("Unknown current working directory!");

Self::load_upwards_from(working_dir)
Self::load_upwards_from(working_dir, false)
}

pub fn load_upwards_from<P>(starting_dir: P) -> miette::Result<Self>
pub fn load_upwards_from<P>(starting_dir: P, stop_at_first: bool) -> miette::Result<Self>
where
P: AsRef<Path>,
{
trace!("Traversing upwards and loading all .prototools files");
trace!("Traversing upwards and loading .prototools files");

let mut current_dir = Some(starting_dir.as_ref());
let mut config = ToolsConfig::default();
Expand All @@ -95,6 +101,10 @@ impl ToolsConfig {
parent_config.merge(config);

config = parent_config;

if stop_at_first {
break;
}
}

match dir.parent() {
Expand Down
3 changes: 2 additions & 1 deletion crates/core/tests/tools_config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ foo = "source:./test.toml"
"#,
);

let config = ToolsConfig::load_upwards_from(sandbox.path().join("one/two/three")).unwrap();
let config =
ToolsConfig::load_upwards_from(sandbox.path().join("one/two/three"), false).unwrap();

assert_eq!(
config.tools,
Expand Down

0 comments on commit 40407b7

Please sign in to comment.