Skip to content
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
2 changes: 2 additions & 0 deletions .cursor/rules/development.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ alwaysApply: true
- `mise run lint-fix` - run linting and fix issues

Don't run e2e tests by trying to execute them directly, always use `mise run test:e2e [test_filename]...`

Run `mise run lint-fix` and `git add` any lint fixes before trying to commit.
6 changes: 6 additions & 0 deletions e2e/plugins/test_tiny_shim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

mise use tiny@latest

# The shim should output the passed arguments in the correct order
assert "$HOME/.local/share/mise/shims/rtx-tiny --no-config --env foo --jobs 2 --raw --yes extra-arg" "rtx-tiny: v3.1.0 args: --no-config --env foo --jobs 2 --raw --yes extra-arg"
8 changes: 1 addition & 7 deletions src/cli/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,7 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
pub static V: Lazy<Versioning> = Lazy::new(|| Versioning::new(env!("CARGO_PKG_VERSION")).unwrap());

pub fn print_version_if_requested(args: &[String]) -> std::io::Result<bool> {
#[cfg(unix)]
let mise_bin = "mise";
#[cfg(windows)]
let mise_bin = "mise.exe";
if args.len() == 2
&& (*env::MISE_BIN_NAME == mise_bin || env::MISE_BIN_NAME.starts_with("mise-"))
{
if args.len() == 2 && !*crate::env::IS_RUNNING_AS_SHIM {
let cmd = &args[1].to_lowercase();
if cmd == "version" || cmd == "-v" || cmd == "--version" || cmd == "v" {
show_version()?;
Expand Down
29 changes: 16 additions & 13 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,15 @@ impl Settings {

pub fn add_cli_matches(cli: &Cli) {
let mut s = SettingsPartial::empty();
for arg in &*env::ARGS.read().unwrap() {
if arg == "--" {
break;
}
if arg == "--raw" {
s.raw = Some(true);
}

// Don't process mise-specific flags when running as a shim
if *crate::env::IS_RUNNING_AS_SHIM {
Self::reset(Some(s));
return;
}

if cli.raw {
s.raw = Some(true);
}
if let Some(cd) = &cli.cd {
s.cd = Some(cd.clone());
Expand Down Expand Up @@ -458,12 +460,13 @@ impl Settings {

pub fn no_config() -> bool {
*env::MISE_NO_CONFIG
|| env::ARGS
.read()
.unwrap()
.iter()
.take_while(|a| *a != "--")
.any(|a| a == "--no-config")
|| !*crate::env::IS_RUNNING_AS_SHIM
&& env::ARGS
.read()
.unwrap()
.iter()
.take_while(|a| *a != "--")
.any(|a| a == "--no-config")
}
}

Expand Down
57 changes: 40 additions & 17 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ pub static __USAGE: Lazy<Option<String>> = Lazy::new(|| var("__USAGE").ok());
// true if running inside a shim
pub static __MISE_SHIM: Lazy<bool> = Lazy::new(|| var_is_true("__MISE_SHIM"));

// true if the current process is running as a shim (not direct mise invocation)
pub static IS_RUNNING_AS_SHIM: Lazy<bool> = Lazy::new(|| {
// When running tests, always treat as direct mise invocation
// to avoid interfering with test expectations
if cfg!(test) {
return false;
}

#[cfg(unix)]
let mise_bin = "mise";
#[cfg(windows)]
let mise_bin = "mise.exe";
let bin_name = *MISE_BIN_NAME;
bin_name != mise_bin && !bin_name.starts_with("mise-")
});

#[cfg(test)]
pub static TERM_WIDTH: Lazy<usize> = Lazy::new(|| 80);

Expand Down Expand Up @@ -444,23 +460,30 @@ fn prefer_offline(args: &[String]) -> bool {
fn environment(args: &[String]) -> Vec<String> {
let arg_defs = HashSet::from(["--profile", "-P", "--env", "-E"]);

args.windows(2)
.take_while(|window| !window.iter().any(|a| a == "--"))
.find_map(|window| {
if arg_defs.contains(&*window[0]) {
Some(window[1].clone())
} else {
None
}
})
.or_else(|| var("MISE_ENV").ok())
.or_else(|| var("MISE_PROFILE").ok())
.or_else(|| var("MISE_ENVIRONMENT").ok())
.unwrap_or_default()
.split(',')
.filter(|s| !s.is_empty())
.map(String::from)
.collect()
// Get environment value from args or env vars
if *IS_RUNNING_AS_SHIM {
// When running as shim, ignore command line args and use env vars only
None
} else {
// Try to get from command line args first
args.windows(2)
.take_while(|window| !window.iter().any(|a| a == "--"))
.find_map(|window| {
if arg_defs.contains(&*window[0]) {
Some(window[1].clone())
} else {
None
}
})
}
.or_else(|| var("MISE_ENV").ok())
.or_else(|| var("MISE_PROFILE").ok())
.or_else(|| var("MISE_ENVIRONMENT").ok())
.unwrap_or_default()
.split(',')
.filter(|s| !s.is_empty())
.map(String::from)
.collect()
}

fn log_file_level() -> Option<LevelFilter> {
Expand Down
Loading