-
-
Notifications
You must be signed in to change notification settings - Fork 949
feat: allow set/unset backend aliases #6172
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(()) | ||
| } | ||
|
|
||
| pub fn set_alias(&mut self, fa: &BackendArg, from: &str, to: &str) -> eyre::Result<()> { | ||
| self.alias | ||
| .entry(fa.short.to_string()) | ||
|
|
@@ -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(()) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Backend Alias Removal Causes Data LossThe |
||
|
|
||
| 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); | ||
|
|
||
There was a problem hiding this comment.
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_aliasandremove_backend_aliasmethods only update the TOML document. They miss updating the in-memoryself.aliasstructure, which can lead to inconsistencies between the in-memory state and the persisted configuration. Existing methods likeset_aliascorrectly update both.Additional Locations (1)
src/config/config_file/mise_toml.rs#L192-L203