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 require version for mise sh --unset #3628

Merged
merged 2 commits into from
Dec 17, 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
2 changes: 1 addition & 1 deletion docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Can also use `MISE_NO_CONFIG=1`
- [`mise settings ls [FLAGS] [KEY]`](/cli/settings/ls.md)
- [`mise settings set [-l --local] <KEY> <VALUE>`](/cli/settings/set.md)
- [`mise settings unset [-l --local] <KEY>`](/cli/settings/unset.md)
- [`mise shell [FLAGS] [TOOL@VERSION]...`](/cli/shell.md)
- [`mise shell [FLAGS] <TOOL@VERSION>...`](/cli/shell.md)
- [`mise sync <SUBCOMMAND>`](/cli/sync.md)
- [`mise sync node [FLAGS]`](/cli/sync/node.md)
- [`mise sync python [--pyenv] [--uv]`](/cli/sync/python.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/cli/shell.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `mise shell`

- **Usage**: `mise shell [FLAGS] [TOOL@VERSION]...`
- **Usage**: `mise shell [FLAGS] <TOOL@VERSION>...`
- **Aliases**: `sh`
- **Source code**: [`src/cli/shell.rs`](https://github.com/jdx/mise/blob/main/src/cli/shell.rs)

Expand All @@ -13,7 +13,7 @@ such as `MISE_NODE_VERSION=20` which is "eval"ed as a shell function created by

## Arguments

### `[TOOL@VERSION]...`
### `<TOOL@VERSION>...`

Tool(s) to use

Expand Down
2 changes: 1 addition & 1 deletion mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ such as `MISE_NODE_VERSION=20` which is "eval"ed as a shell function created by
}
flag "--raw" help="Directly pipe stdin/stdout/stderr from plugin to user Sets --jobs=1"
flag "-u --unset" help="Removes a previously set version"
arg "[TOOL@VERSION]..." help="Tool(s) to use" var=true
arg "<TOOL@VERSION>..." help="Tool(s) to use" var=true
}
cmd "sync" subcommand_required=true help="Synchronize tools from other version managers with mise" {
cmd "node" help="Symlinks all tool versions from an external tool into mise" {
Expand Down
28 changes: 18 additions & 10 deletions src/cli/shell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use color_eyre::eyre::{eyre, Result};
use console::style;
use heck::ToShoutySnakeCase;
use indoc::formatdoc;

use crate::cli::args::ToolArg;
Expand All @@ -18,7 +19,7 @@ use crate::toolset::{InstallOptions, ToolSource, ToolsetBuilder};
#[clap(verbatim_doc_comment, visible_alias = "sh", after_long_help = AFTER_LONG_HELP)]
pub struct Shell {
/// Tool(s) to use
#[clap(value_name = "TOOL@VERSION")]
#[clap(value_name = "TOOL@VERSION", required = true)]
tool: Vec<ToolArg>,

/// Number of jobs to run in parallel
Expand All @@ -43,6 +44,19 @@ impl Shell {
err_inactive()?;
}

let shell = get_shell(None).expect("no shell detected");

if self.unset {
for ta in &self.tool {
let op = shell.unset_env(&format!(
"MISE_{}_VERSION",
ta.ba.short.to_shouty_snake_case()
));
print!("{op}");
}
return Ok(());
}

let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
let opts = InstallOptions {
force: false,
Expand All @@ -53,18 +67,12 @@ impl Shell {
ts.install_missing_versions(&opts)?;
ts.notify_if_versions_missing();

let shell = get_shell(None).expect("no shell detected");

for (p, tv) in ts.list_current_installed_versions() {
let source = &ts.versions.get(p.ba()).unwrap().source;
if matches!(source, ToolSource::Argument) {
let k = format!("MISE_{}_VERSION", p.id().to_uppercase());
let op = if self.unset {
shell.unset_env(&k)
} else {
shell.set_env(&k, &tv.version)
};
miseprintln!("{op}");
let k = format!("MISE_{}_VERSION", p.id().to_shouty_snake_case());
let op = shell.set_env(&k, &tv.version);
print!("{op}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion xtasks/fig/src/mise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2288,7 +2288,7 @@ const completionSpec: Fig.Spec = {
{
"name": "tool@version",
"description": "Tool(s) to use",
"isOptional": true,
"isOptional": false,
"isVariadic": true,
"generators": toolVersionGenerator
}
Expand Down
Loading