Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not reuse local tool options for mise use -g #3469

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions e2e/cli/test_use_retain_opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

assert "mise use dummy[foo=bar]@1.0.0"
assert "cat mise.toml" '[tools]
dummy = { version = "1.0.0", foo = "bar" }'
assert "mise use -g dummy@1.0.0"
assert "cat ~/.config/mise/config.toml" '[tools]
dummy = "1.0.0"'
4 changes: 3 additions & 1 deletion src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ pub struct Use {
impl Use {
pub fn run(self) -> Result<()> {
let config = Config::try_get()?;
let mut ts = ToolsetBuilder::new().build(&config)?;
let mut ts = ToolsetBuilder::new()
.with_global_only(self.global)
.build(&config)?;
let mpr = MultiProgressReport::get();
let mut cf = self.get_config_file()?;
let mut resolve_options = ResolveOptions {
Expand Down
11 changes: 10 additions & 1 deletion src/toolset/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use itertools::Itertools;

use crate::cli::args::{BackendArg, ToolArg};
use crate::config::Config;
use crate::env;
use crate::errors::Error;
use crate::toolset::{ToolRequest, ToolSource, Toolset};
use crate::{config, env};

#[derive(Debug, Default)]
pub struct ToolsetBuilder {
args: Vec<ToolArg>,
global_only: bool,
default_to_latest: bool,
}

Expand All @@ -30,6 +31,11 @@ impl ToolsetBuilder {
self
}

pub fn with_global_only(mut self, global_only: bool) -> Self {
self.global_only = global_only;
self
}

pub fn build(self, config: &Config) -> Result<Toolset> {
let mut toolset = Toolset {
..Default::default()
Expand All @@ -50,6 +56,9 @@ impl ToolsetBuilder {

fn load_config_files(&self, config: &Config, ts: &mut Toolset) -> eyre::Result<()> {
for cf in config.config_files.values().rev() {
if self.global_only && !config::is_global_config(cf.get_path()) {
continue;
}
ts.merge(cf.to_toolset()?);
}
Ok(())
Expand Down
Loading