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
3 changes: 2 additions & 1 deletion docs/cli/set.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ Can be used multiple times. Requires --age-encrypt.
The TOML file to update

Can be a file path or directory. If a directory is provided, will create/use mise.toml in that directory.
Defaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or `mise.toml`.
Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`.
Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.

### `--no-redact`

Expand Down
2 changes: 2 additions & 0 deletions docs/cli/unset.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ e.g.: NODE_ENV

Specify a file to use instead of `mise.toml`

Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`. Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.

### `-g --global`

Use the global config file
Expand Down
4 changes: 3 additions & 1 deletion docs/cli/unuse.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ In the following order:
- If `--global` is set, it will use the global config file.
- If `--path` is set, it will use the config file at the given path.
- If `--env` is set, it will use `mise.<env>.toml`.
- If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead.
- If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead.
- If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.
- Otherwise just "mise.toml" or global config if cwd is home directory.

Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.

Will also prune the installed version if no other configurations are using it.

## Arguments
Expand Down
4 changes: 3 additions & 1 deletion docs/cli/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ In the following order:
- If `--global` is set, it will use the global config file.
- If `--path` is set, it will use the config file at the given path.
- If `--env` is set, it will use `mise.<env>.toml`.
- If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead.
- If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead.
- If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.
- Otherwise just "mise.toml" or global config if cwd is home directory.

Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.

Use the `--global` flag to use the global config file instead.

## Arguments
Expand Down
11 changes: 11 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,17 @@ Default: `$MISE_CONFIG_DIR/config.toml` (Usually `~/.config/mise/config.toml`)

This is the path to the config file.

Use this when you want global writes, such as `mise use` or `mise set` run from
`$HOME`, to target a different config file. [`MISE_DEFAULT_CONFIG_FILENAME`](#mise_default_config_filename)
customizes the default local config filename, not the global config path.

### `MISE_DEFAULT_CONFIG_FILENAME`

Default: `mise.toml`

This customizes the default local config filename used when mise creates or
looks for project config files.

### `MISE_GLOBAL_CONFIG_ROOT`

Default: `$HOME`
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Settings from '/components/settings.vue';
</script>

The following is a list of all of mise's settings. These can be set via `mise settings key=value`,
by directly modifying `~/.config/mise/config.toml` or local config, or via environment variables.
by directly modifying the [global config file](/configuration.html#mise_global_config_file)
(`~/.config/mise/config.toml`) or local config, or via environment variables.

Some of them also can be set via global CLI flags.

Expand Down
28 changes: 28 additions & 0 deletions e2e/cli/test_global_config_file_home
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

mkdir -p "$HOME/.config/mise"
cat >"$HOME/.config/mise/config.toml" <<'TOML'
[env]
LOCAL_ONLY = "true"
TOML
cat >"$HOME/.config/mise/config-global.toml" <<'TOML'
[env]
GLOBAL_ONLY = "true"
TOML
export MISE_GLOBAL_CONFIG_FILE="$HOME/.config/mise/config-global.toml"

cd "$HOME" || exit 1

assert "mise set FOO=bar" ""
assert_contains "cat $HOME/.config/mise/config-global.toml" 'FOO = "bar"'
assert_not_contains "cat $HOME/.config/mise/config.toml" "FOO"

assert "mise unset FOO" ""
assert_not_contains "cat $HOME/.config/mise/config-global.toml" "FOO"

assert_contains "mise use dummy@system" "mise ~/.config/mise/config-global.toml tools: dummy@system"
assert_contains "cat $HOME/.config/mise/config-global.toml" 'dummy = "system"'
assert_not_contains "cat $HOME/.config/mise/config.toml" "dummy"

assert_contains "mise unuse -y dummy 2>&1" "mise removed: dummy from ~/.config/mise/config-global.toml"
assert_not_contains "cat $HOME/.config/mise/config-global.toml" "dummy"
13 changes: 10 additions & 3 deletions man/man1/mise.1
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,8 @@ Render completions
The TOML file to update

Can be a file path or directory. If a directory is provided, will create/use mise.toml in that directory.
Defaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or `mise.toml`.
Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`.
Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.
.TP
\fB\-\-no\-redact\fR
Show raw values instead of redacting secrets
Expand Down Expand Up @@ -3303,6 +3304,8 @@ By default, this command modifies `mise.toml` in the current directory.
.TP
\fB\-f, \-\-file\fR \fI<FILE>\fR
Specify a file to use instead of `mise.toml`

Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`. Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.
.TP
\fB\-g, \-\-global\fR
Use the global config file
Expand Down Expand Up @@ -3334,10 +3337,12 @@ In the following order:
\- If `\-\-global` is set, it will use the global config file.
\- If `\-\-path` is set, it will use the config file at the given path.
\- If `\-\-env` is set, it will use `mise.<env>.toml`.
\- If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead.
\- If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead.
\- If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.
\- Otherwise just "mise.toml" or global config if cwd is home directory.

Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.

Will also prune the installed version if no other configurations are using it.
.PP
\fBUsage:\fR mise unuse [OPTIONS] <INSTALLED_TOOL@VERSION> ...
Expand Down Expand Up @@ -3445,10 +3450,12 @@ In the following order:
\- If `\-\-global` is set, it will use the global config file.
\- If `\-\-path` is set, it will use the config file at the given path.
\- If `\-\-env` is set, it will use `mise.<env>.toml`.
\- If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead.
\- If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead.
\- If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.
\- Otherwise just "mise.toml" or global config if cwd is home directory.

Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.

Use the `\-\-global` flag to use the global config file instead.
.PP
\fBUsage:\fR mise use [OPTIONS] [<TOOL@VERSION>] ...
Expand Down
7 changes: 4 additions & 3 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ cmd set help="Set environment variables in mise.toml" {
}
flag --complete help="Render completions" hide=#true
flag --file help="The TOML file to update" {
long_help "The TOML file to update\n\nCan be a file path or directory. If a directory is provided, will create/use mise.toml in that directory.\nDefaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or `mise.toml`."
long_help "The TOML file to update\n\nCan be a file path or directory. If a directory is provided, will create/use mise.toml in that directory.\nDefaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`.\nUse [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path."
arg <FILE>
}
flag --no-redact help="Show raw values instead of redacting secrets"
Expand Down Expand Up @@ -1343,6 +1343,7 @@ cmd unset help="Remove environment variable(s) from the config file." {
long_help "Remove environment variable(s) from the config file.\n\nBy default, this command modifies `mise.toml` in the current directory."
after_long_help "Examples:\n\n # Remove NODE_ENV from the current directory's config\n $ mise unset NODE_ENV\n\n # Remove NODE_ENV from the global config\n $ mise unset NODE_ENV -g\n"
flag "-f --file" help="Specify a file to use instead of `mise.toml`" {
long_help "Specify a file to use instead of `mise.toml`\n\nDefaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`. Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path."
arg <FILE>
}
flag "-g --global" help="Use the global config file"
Expand All @@ -1353,7 +1354,7 @@ cmd untrust help="No longer trust a config, will prompt in the future" {
}
cmd unuse help="Removes installed tool versions from mise.toml" {
alias rm remove
long_help "Removes installed tool versions from mise.toml\n\nBy default, this will use the `mise.toml` file that has the tool defined.\nIf multiple config files exist (e.g., both `mise.toml` and `mise.local.toml`),\nthe lowest precedence file (`mise.toml`) will be used.\nSee https://mise.en.dev/configuration.html#target-file-for-write-operations\n\nIn the following order:\n - If `--global` is set, it will use the global config file.\n - If `--path` is set, it will use the config file at the given path.\n - If `--env` is set, it will use `mise.<env>.toml`.\n - If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead.\n - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.\n - Otherwise just \"mise.toml\" or global config if cwd is home directory.\n\nWill also prune the installed version if no other configurations are using it."
long_help "Removes installed tool versions from mise.toml\n\nBy default, this will use the `mise.toml` file that has the tool defined.\nIf multiple config files exist (e.g., both `mise.toml` and `mise.local.toml`),\nthe lowest precedence file (`mise.toml`) will be used.\nSee https://mise.en.dev/configuration.html#target-file-for-write-operations\n\nIn the following order:\n - If `--global` is set, it will use the global config file.\n - If `--path` is set, it will use the config file at the given path.\n - If `--env` is set, it will use `mise.<env>.toml`.\n - If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead.\n - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.\n - Otherwise just \"mise.toml\" or global config if cwd is home directory.\n\nUse [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.\n\nWill also prune the installed version if no other configurations are using it."
after_long_help "Examples:\n\n # will uninstall specific version\n $ mise unuse node@18.0.0\n\n # will uninstall specific version from global config\n $ mise unuse -g node@18.0.0\n\n # will uninstall specific version from .mise.local.toml\n $ mise unuse --env local node@20\n\n # will uninstall specific version from .mise.staging.toml\n $ mise unuse --env staging node@20\n"
flag "-e --env" help="Create/modify an environment-specific config file like .mise.<env>.toml" {
arg <ENV>
Expand Down Expand Up @@ -1400,7 +1401,7 @@ cmd usage hide=#true help="Generate a usage CLI spec" {
}
cmd use help="Installs a tool and adds the version to mise.toml." {
alias u
long_help "Installs a tool and adds the version to mise.toml.\n\nThis will install the tool version if it is not already installed.\nBy default, this will use a `mise.toml` file in the current directory.\nIf multiple config files exist (e.g., both `mise.toml` and `mise.local.toml`),\nthe lowest precedence file (`mise.toml`) will be used.\nSee https://mise.en.dev/configuration.html#target-file-for-write-operations\n\nIn the following order:\n - If `--global` is set, it will use the global config file.\n - If `--path` is set, it will use the config file at the given path.\n - If `--env` is set, it will use `mise.<env>.toml`.\n - If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead.\n - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.\n - Otherwise just \"mise.toml\" or global config if cwd is home directory.\n\nUse the `--global` flag to use the global config file instead."
long_help "Installs a tool and adds the version to mise.toml.\n\nThis will install the tool version if it is not already installed.\nBy default, this will use a `mise.toml` file in the current directory.\nIf multiple config files exist (e.g., both `mise.toml` and `mise.local.toml`),\nthe lowest precedence file (`mise.toml`) will be used.\nSee https://mise.en.dev/configuration.html#target-file-for-write-operations\n\nIn the following order:\n - If `--global` is set, it will use the global config file.\n - If `--path` is set, it will use the config file at the given path.\n - If `--env` is set, it will use `mise.<env>.toml`.\n - If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead.\n - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.\n - Otherwise just \"mise.toml\" or global config if cwd is home directory.\n\nUse [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.\n\nUse the `--global` flag to use the global config file instead."
after_long_help "Examples:\n\n # run with no arguments to use the interactive selector\n $ mise use\n\n # set the current version of node to 20.x in mise.toml of current directory\n # will write the fuzzy version (e.g.: 20)\n $ mise use node@20\n\n # set the current version of node to 20.x in ~/.config/mise/config.toml\n # will write the precise version (e.g.: 20.0.0)\n $ mise use -g --pin node@20\n\n # sets .mise.local.toml (which is intended not to be committed to a project)\n $ mise use --env local node@20\n\n # sets .mise.staging.toml (which is used if MISE_ENV=staging)\n $ mise use --env staging node@20\n"
flag "-e --env" help="Create/modify an environment-specific config file like .mise.<env>.toml" {
arg <ENV>
Expand Down
3 changes: 2 additions & 1 deletion src/cli/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ pub struct Set {
/// The TOML file to update
///
/// Can be a file path or directory. If a directory is provided, will create/use mise.toml in that directory.
/// Defaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or `mise.toml`.
/// Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`.
/// Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.
#[clap(long, verbatim_doc_comment, required = false, value_hint = clap::ValueHint::AnyPath)]
file: Option<PathBuf>,

Expand Down
20 changes: 12 additions & 8 deletions src/cli/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use eyre::Result;

use crate::config::config_file::ConfigFile;
use crate::config::config_file::mise_toml::MiseToml;
use crate::{config, env};
use crate::config::{ConfigPathOptions, resolve_target_config_path};

/// Remove environment variable(s) from the config file.
///
Expand All @@ -18,6 +18,9 @@ pub struct Unset {
keys: Vec<String>,

/// Specify a file to use instead of `mise.toml`
///
/// Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`.
/// Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.
#[clap(short, long, value_hint = clap::ValueHint::FilePath)]
file: Option<PathBuf>,

Expand All @@ -39,13 +42,14 @@ const AFTER_LONG_HELP: &str = color_print::cstr!(

impl Unset {
pub async fn run(self) -> Result<()> {
let filename = if let Some(file) = &self.file {
file.clone()
} else if self.global {
config::global_config_path()
} else {
config::top_toml_config().unwrap_or(env::MISE_DEFAULT_CONFIG_FILENAME.clone().into())
};
let filename = resolve_target_config_path(ConfigPathOptions {
global: self.global,
path: self.file.clone(),
env: None,
cwd: None,
prefer_toml: true,
prevent_home_local: true,
})?;

let mut config = MiseToml::from_file(&filename).unwrap_or_default();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Using unwrap_or_default() when loading the TOML file means that if there is a syntax error or any other parsing failure in an existing configuration file, mise unset will silently discard the entire file's contents and overwrite it with an empty configuration. This can lead to accidental data loss.

Instead, we should check if the file exists, propagate any parsing errors using ? so the user is notified of the syntax error, and only initialize a default configuration if the file does not exist.

Suggested change
let mut config = MiseToml::from_file(&filename).unwrap_or_default();
let mut config = if filename.exists() {
MiseToml::from_file(&filename)?
} else {
MiseToml::init(&filename)
};


Expand Down
4 changes: 3 additions & 1 deletion src/cli/unuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ use path_absolutize::Absolutize;
/// - If `--global` is set, it will use the global config file.
/// - If `--path` is set, it will use the config file at the given path.
/// - If `--env` is set, it will use `mise.<env>.toml`.
/// - If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead.
/// - If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead.
/// - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.
/// - Otherwise just "mise.toml" or global config if cwd is home directory.
///
/// Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.
///
/// Will also prune the installed version if no other configurations are using it.
#[derive(Debug, clap::Args)]
#[clap(verbatim_doc_comment, visible_aliases = ["rm", "remove"], after_long_help = AFTER_LONG_HELP)]
Expand Down
4 changes: 3 additions & 1 deletion src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ use crate::{config, env, exit, file};
/// - If `--global` is set, it will use the global config file.
/// - If `--path` is set, it will use the config file at the given path.
/// - If `--env` is set, it will use `mise.<env>.toml`.
/// - If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead.
/// - If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead.
/// - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.
/// - Otherwise just "mise.toml" or global config if cwd is home directory.
///
/// Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.
///
/// Use the `--global` flag to use the global config file instead.
#[derive(Debug, clap::Args)]
#[clap(verbatim_doc_comment, visible_alias = "u", after_long_help = AFTER_LONG_HELP)]
Expand Down
Loading