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: 1 addition & 1 deletion docs/cli/alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Don't show table header
- [`mise alias get <PLUGIN> <ALIAS>`](/cli/alias/get.md)
- [`mise alias ls [--no-header] [TOOL]`](/cli/alias/ls.md)
- [`mise alias set <ARGS>…`](/cli/alias/set.md)
- [`mise alias unset <PLUGIN> <ALIAS>`](/cli/alias/unset.md)
- [`mise alias unset <PLUGIN> [ALIAS]`](/cli/alias/unset.md)
7 changes: 4 additions & 3 deletions docs/cli/alias/set.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@
- **Aliases**: `add`, `create`
- **Source code**: [`src/cli/alias/set.rs`](https://github.com/jdx/mise/blob/main/src/cli/alias/set.rs)

Add/update an alias for a plugin
Add/update an alias for a backend/plugin

This modifies the contents of ~/.config/mise/config.toml

## Arguments

### `<PLUGIN>`

The plugin to set the alias for
The backend/plugin to set the alias for

### `<ALIAS>`

The alias to set

### `<VALUE>`
### `[VALUE]`

The value to set the alias to

Examples:

```
mise alias set maven asdf:mise-plugins/mise-maven
mise alias set node lts-jod 22.0.0
```
9 changes: 5 additions & 4 deletions docs/cli/alias/unset.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# `mise alias unset`

- **Usage**: `mise alias unset <PLUGIN> <ALIAS>`
- **Usage**: `mise alias unset <PLUGIN> [ALIAS]`
- **Aliases**: `rm`, `remove`, `delete`, `del`
- **Source code**: [`src/cli/alias/unset.rs`](https://github.com/jdx/mise/blob/main/src/cli/alias/unset.rs)

Clears an alias for a plugin
Clears an alias for a backend/plugin

This modifies the contents of ~/.config/mise/config.toml

## Arguments

### `<PLUGIN>`

The plugin to remove the alias from
The backend/plugin to remove the alias from

### `<ALIAS>`
### `[ALIAS]`

The alias to remove

Examples:

```
mise alias unset maven
mise alias unset node lts-jod
```
2 changes: 1 addition & 1 deletion docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Can also use `MISE_NO_CONFIG=1`
- [`mise alias get <PLUGIN> <ALIAS>`](/cli/alias/get.md)
- [`mise alias ls [--no-header] [TOOL]`](/cli/alias/ls.md)
- [`mise alias set <ARGS>…`](/cli/alias/set.md)
- [`mise alias unset <PLUGIN> <ALIAS>`](/cli/alias/unset.md)
- [`mise alias unset <PLUGIN> [ALIAS]`](/cli/alias/unset.md)
- [`mise backends <SUBCOMMAND>`](/cli/backends.md)
- [`mise backends ls`](/cli/backends/ls.md)
- [`mise bin-paths [TOOL@VERSION]…`](/cli/bin-paths.md)
Expand Down
2 changes: 1 addition & 1 deletion e2e/cli/test_alias
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ assert_contains "mise alias ls tiny" "tiny xxx 2"
assert "mise alias unset tiny xxx"
assert_not_contains "mise alias ls" "tiny xxx"

assert "mise config set alias.nushell aqua:nushell/nushell"
assert "mise alias set nushell aqua:nushell/nushell"
assert "mise x nushell -- nu --version"
20 changes: 10 additions & 10 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ cmd alias help="Manage version aliases." {
flag --no-header help="Don't show table header"
arg "[TOOL]" help="Show aliases for <TOOL>" required=#false
}
cmd set help="Add/update an alias for a plugin" {
cmd set help="Add/update an alias for a backend/plugin" {
alias add create
long_help "Add/update an alias for a plugin\n\nThis modifies the contents of ~/.config/mise/config.toml"
after_long_help "Examples:\n\n $ mise alias set node lts-jod 22.0.0\n"
arg <PLUGIN> help="The plugin to set the alias for"
long_help "Add/update an alias for a backend/plugin\n\nThis modifies the contents of ~/.config/mise/config.toml"
after_long_help "Examples:\n\n $ mise alias set maven asdf:mise-plugins/mise-maven\n $ mise alias set node lts-jod 22.0.0\n"
arg <PLUGIN> help="The backend/plugin to set the alias for"
arg <ALIAS> help="The alias to set"
arg <VALUE> help="The value to set the alias to"
arg "[VALUE]" help="The value to set the alias to" required=#false
}
cmd unset help="Clears an alias for a plugin" {
cmd unset help="Clears an alias for a backend/plugin" {
alias rm remove delete del
long_help "Clears an alias for a plugin\n\nThis modifies the contents of ~/.config/mise/config.toml"
after_long_help "Examples:\n\n $ mise alias unset node lts-jod\n"
arg <PLUGIN> help="The plugin to remove the alias from"
arg <ALIAS> help="The alias to remove"
long_help "Clears an alias for a backend/plugin\n\nThis modifies the contents of ~/.config/mise/config.toml"
after_long_help "Examples:\n\n $ mise alias unset maven\n $ mise alias unset node lts-jod\n"
arg <PLUGIN> help="The backend/plugin to remove the alias from"
arg "[ALIAS]" help="The alias to remove" required=#false
}
}
cmd asdf hide=#true help="[internal] simulates asdf for plugins that call \"asdf\" internally" {
Expand Down
12 changes: 8 additions & 4 deletions src/cli/alias/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@ use crate::cli::args::BackendArg;
use crate::config::Config;
use crate::config::config_file::ConfigFile;

/// Add/update an alias for a plugin
/// Add/update an alias for a backend/plugin
///
/// This modifies the contents of ~/.config/mise/config.toml
#[derive(Debug, clap::Args)]
#[clap(visible_aliases = ["add", "create"], after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)]
pub struct AliasSet {
/// The plugin to set the alias for
/// The backend/plugin to set the alias for
pub plugin: BackendArg,
/// The alias to set
pub alias: String,
/// The value to set the alias to
pub value: String,
pub value: Option<String>,
}

impl AliasSet {
pub async fn run(self) -> Result<()> {
let mut global_config = Config::get().await?.global_config()?;
global_config.set_alias(&self.plugin, &self.alias, &self.value)?;
match &self.value {
None => global_config.set_backend_alias(&self.plugin, &self.alias)?,
Some(val) => global_config.set_alias(&self.plugin, &self.alias, val)?,
}
global_config.save()
}
}

static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>

$ <bold>mise alias set maven asdf:mise-plugins/mise-maven</bold>
$ <bold>mise alias set node lts-jod 22.0.0</bold>
"#
);
16 changes: 12 additions & 4 deletions src/cli/alias/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,37 @@ use crate::cli::args::BackendArg;
use crate::config::Config;
use crate::config::config_file::ConfigFile;

/// Clears an alias for a plugin
/// Clears an alias for a backend/plugin
///
/// This modifies the contents of ~/.config/mise/config.toml
#[derive(Debug, clap::Args)]
#[clap(visible_aliases = ["rm", "remove", "delete", "del"], after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)]
pub struct AliasUnset {
/// The plugin to remove the alias from
/// The backend/plugin to remove the alias from
pub plugin: BackendArg,
/// The alias to remove
pub alias: String,
pub alias: Option<String>,
}

impl AliasUnset {
pub async fn run(self) -> Result<()> {
let mut global_config = Config::get().await?.global_config()?;
global_config.remove_alias(&self.plugin, &self.alias)?;
match self.alias {
None => {
global_config.remove_backend_alias(&self.plugin)?;
}
Some(ref alias) => {
global_config.remove_alias(&self.plugin, alias)?;
}
}
global_config.save()
}
}

static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>

$ <bold>mise alias unset maven</bold>
$ <bold>mise alias unset node lts-jod</bold>
"#
);
24 changes: 24 additions & 0 deletions src/config/config_file/mise_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ impl MiseToml {
Ok(self.doc.lock().unwrap())
}

pub fn set_backend_alias(&mut self, fa: &BackendArg, to: &str) -> eyre::Result<()> {
self.doc_mut()?
.get_mut()
.unwrap()
.entry("alias")
.or_insert_with(table)
.as_table_like_mut()
.unwrap()
.insert(&fa.short, value(to));
Ok(())
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Alias Methods Fail to Update In-Memory State

The set_backend_alias and remove_backend_alias methods only update the TOML document. They miss updating the in-memory self.alias structure, which can lead to inconsistencies between the in-memory state and the persisted configuration. Existing methods like set_alias correctly update both.

Additional Locations (1)

Fix in Cursor Fix in Web


pub fn set_alias(&mut self, fa: &BackendArg, from: &str, to: &str) -> eyre::Result<()> {
self.alias
.entry(fa.short.to_string())
Expand All @@ -178,6 +190,18 @@ impl MiseToml {
Ok(())
}

pub fn remove_backend_alias(&mut self, fa: &BackendArg) -> eyre::Result<()> {
let mut doc = self.doc_mut()?;
let doc = doc.get_mut().unwrap();
if let Some(aliases) = doc.get_mut("alias").and_then(|v| v.as_table_mut()) {
aliases.remove(&fa.short);
if aliases.is_empty() {
doc.as_table_mut().remove("alias");
}
}
Ok(())
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Backend Alias Removal Causes Data Loss

The remove_backend_alias method has two issues. Unlike remove_alias, it updates only the TOML document, leaving the in-memory self.alias out of sync. Additionally, it removes the entire tool entry from the TOML, including any version aliases, instead of just the backend alias. This can lead to unexpected data loss and inconsistencies.

Fix in Cursor Fix in Web


pub fn remove_alias(&mut self, fa: &BackendArg, from: &str) -> eyre::Result<()> {
if let Some(aliases) = self.alias.get_mut(&fa.short) {
aliases.versions.shift_remove(from);
Expand Down
10 changes: 6 additions & 4 deletions xtasks/fig/src/mise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,11 @@ const completionSpec: Fig.Spec = {
},
{
name: ["set", "add", "create"],
description: "Add/update an alias for a plugin",
description: "Add/update an alias for a backend/plugin",
args: [
{
name: "plugin",
description: "The plugin to set the alias for",
description: "The backend/plugin to set the alias for",
generators: pluginGenerator,
debounce: true,
},
Expand All @@ -596,22 +596,24 @@ const completionSpec: Fig.Spec = {
{
name: "value",
description: "The value to set the alias to",
isOptional: true,
},
],
},
{
name: ["unset", "rm", "remove", "delete", "del"],
description: "Clears an alias for a plugin",
description: "Clears an alias for a backend/plugin",
args: [
{
name: "plugin",
description: "The plugin to remove the alias from",
description: "The backend/plugin to remove the alias from",
generators: pluginGenerator,
debounce: true,
},
{
name: "alias",
description: "The alias to remove",
isOptional: true,
generators: aliasGenerator,
debounce: true,
},
Expand Down
Loading