Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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_direct_mise_invocation() {
let cmd = &args[1].to_lowercase();
if cmd == "version" || cmd == "-v" || cmd == "--version" || cmd == "v" {
show_version()?;
Expand Down
40 changes: 36 additions & 4 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,46 @@ impl Settings {
}
}

pub fn add_cli_matches(cli: &Cli) {
let mut s = SettingsPartial::empty();
/// Check if the current process is running as a shim
///
/// Returns true if we're not running as a direct mise invocation,
/// meaning we should pass through flags to the underlying tool.
fn is_running_as_shim() -> bool {
!crate::env::is_direct_mise_invocation()
}

/// Process raw output flag from command line arguments
///
/// This function scans the command line arguments for the `--raw` flag
/// and sets the raw output setting if found. It stops processing
/// at the first `--` argument to avoid processing arguments meant
/// for the underlying tool.
fn process_raw_flag(s: &mut SettingsPartial) {
for arg in &*env::ARGS.read().unwrap() {
if arg == "--" {
break;
}
if arg == "--raw" {
s.raw = Some(true);
break;
}
}
}

pub fn add_cli_matches(cli: &Cli) {
let mut s = SettingsPartial::empty();

// Don't process mise-specific flags when running as a shim
if Self::is_running_as_shim() {
// Only process non-mise-specific flags when running as shim
Self::process_raw_flag(&mut s);
Self::reset(Some(s));
return;
}

// Process all flags when running as mise directly
Self::process_raw_flag(&mut s);

if let Some(cd) = &cli.cd {
s.cd = Some(cd.clone());
}
Expand Down Expand Up @@ -457,13 +487,15 @@ impl Settings {
}

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

Expand Down
30 changes: 30 additions & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,20 @@ fn prefer_offline(args: &[String]) -> bool {
fn environment(args: &[String]) -> Vec<String> {
let arg_defs = HashSet::from(["--profile", "-P", "--env", "-E"]);

// Don't process --env when running as a shim
if !is_direct_mise_invocation() {
// Return environment from env vars only, ignore command line args
return 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();
}

args.windows(2)
.take_while(|window| !window.iter().any(|a| a == "--"))
.find_map(|window| {
Expand Down Expand Up @@ -523,6 +537,22 @@ pub fn set_current_dir<P: AsRef<Path>>(path: P) -> Result<()> {
Ok(())
}

/// Returns true if the current process is a direct mise invocation (not a shim)
pub fn is_direct_mise_invocation() -> bool {
// When running tests, always treat as direct mise invocation
// to avoid interfering with test expectations
if cfg!(test) {
return true;
}

#[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)]
mod tests {
use pretty_assertions::assert_eq;
Expand Down