Skip to content

Commit

Permalink
feat: allow calling mise settings foo=bar as shorthand (#3155)
Browse files Browse the repository at this point in the history
* feat: allow calling `mise settings foo=bar` as shorthand

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
jdx and autofix-ci[bot] authored Nov 23, 2024
1 parent 89b1a5d commit 71d2edf
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Answer yes to all confirmation prompts
- [`mise run [FLAGS]`](/cli/run.md)
- [`mise self-update [FLAGS] [VERSION]`](/cli/self-update.md)
- [`mise set [--file <FILE>] [-g --global] [ENV_VARS]...`](/cli/set.md)
- [`mise settings [--names] <SUBCOMMAND>`](/cli/settings.md)
- [`mise settings [--names] [SETTING] <SUBCOMMAND>`](/cli/settings.md)
- [`mise settings add <SETTING> <VALUE>`](/cli/settings/add.md)
- [`mise settings get <SETTING>`](/cli/settings/get.md)
- [`mise settings ls [--names] [KEY]`](/cli/settings/ls.md)
Expand Down
16 changes: 15 additions & 1 deletion docs/cli/settings.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# `mise settings`

- **Usage**: `mise settings [--names] <SUBCOMMAND>`
- **Usage**: `mise settings [--names] [SETTING] <SUBCOMMAND>`
- **Source code**: [`src/cli/settings.rs`](https://github.com/jdx/mise/blob/main/src/cli/settings.rs)

Manage settings

## Arguments

### `[SETTING]`

## Flags

### `--names`
Expand All @@ -18,3 +22,13 @@ Only display key names for each setting
- [`mise settings ls [--names] [KEY]`](/cli/settings/ls.md)
- [`mise settings set <SETTING> <VALUE>`](/cli/settings/set.md)
- [`mise settings unset <SETTING>`](/cli/settings/unset.md)

Examples:
# list all settings
$ mise settings

# get the value of the setting "always_keep_download"
$ mise settings always_keep_download

# set the value of the setting "always_keep_download" to "true"
$ mise settings always_keep_download=true
2 changes: 1 addition & 1 deletion docs/cli/settings/set.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ The value to set

Examples:

mise settings set legacy_version_file true
mise settings legacy_version_file=true
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ in mise and nvm. Here are some of the supported legacy version files:
| yarn | `.yarnrc` |

In mise these are enabled by default. You can disable them
with `mise settings set legacy_version_file false`.
with `mise settings legacy_version_file=false`.
There is a performance cost to having these when they're parsed as it's performed by the plugin in
`bin/parse-version-file`. However these are [cached](/cache-behavior) so it's not a huge deal.
You may not even notice.
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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 set`,
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.

Some of them also can be set via global CLI flags.
Expand Down
4 changes: 2 additions & 2 deletions docs/dev-tools/backends/vfox.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ The version will be set in `~/.config/mise/config.toml` with the following forma
If you'd like to use vfox plugins by default like on Windows, set the following settings:

```sh
mise settings set asdf false
mise settings set vfox true
mise settings asdf=false
mise settings vfox=true
```

Now you can list available plugins with `mise registry`:
Expand Down
6 changes: 3 additions & 3 deletions docs/lang/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ compiling from source for these platforms.
To use, first set the mirror url to point to the unofficial builds:

```sh
mise settings set node.mirror_url https://unofficial-builds.nodejs.org/download/release/
mise settings node.mirror_url=https://unofficial-builds.nodejs.org/download/release/
```

If your goal is to simply support an alternative arch/os like linux-loong64 or linux-armv6l, this is
Expand All @@ -86,6 +86,6 @@ than what the official binaries are built with).
To use these, set `node.flavor`:

```sh
mise settings set node.flavor musl
mise settings set node.flavor glibc-217
mise settings node.flavor=musl
mise settings node.flavor=glibc-217
```
2 changes: 1 addition & 1 deletion docs/lang/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ That said, there are
some [quirks](https://github.com/indygreg/python-build-standalone/blob/main/docs/quirks.rst)
with the precompiled binaries to be aware of.

If you'd like to disable these binaries, set `mise settings set python.compile 1`.
If you'd like to disable these binaries, set `mise settings python.compile=1`.

These binaries may not work on older CPUs however you may opt into binaries which
are more compatible with older CPUs by setting `MISE_PYTHON_PRECOMPILED_ARCH` with
Expand Down
2 changes: 1 addition & 1 deletion docs/mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ but managed separately with `mise aliases`"
This modifies the contents of ~/.config/mise/config.toml"
after_long_help r"Examples:

$ mise settings set legacy_version_file true
$ mise settings legacy_version_file=true
"
arg "<SETTING>" help="The setting to set"
arg "<VALUE>" help="The value to set"
Expand Down
2 changes: 1 addition & 1 deletion docs/paranoid.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ restrictive for the benefits.
Paranoid mode can be enabled with either `MISE_PARANOID=1` or a setting:

```sh
mise settings set paranoid 1
mise settings paranoid=1
```

## Config files
Expand Down
3 changes: 3 additions & 0 deletions e2e/cli/test_settings_set
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ assert_contains "mise settings" "all_compile = true"
mise settings unset all_compile
assert "mise settings get all_compile" "false"
assert_fail "mise settings get abcdefg" "mise ERROR Unknown setting: abcdefg"
assert "mise settings all_compile" "false"
assert "mise settings all_compile=1"
assert "mise settings all_compile" "true"
2 changes: 1 addition & 1 deletion e2e/plugins/test_tiny
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mise local tiny@latest
assert "mise current tiny" "3.1.0"

# test outdated/upgrade
mise settings set experimental true
mise settings experimental=true
rm -rf "$MISE_DATA_DIR/installs/tiny"
mise use tiny@3
mv "$MISE_DATA_DIR/installs/tiny/"{3.1.0,3.0.0}
Expand Down
2 changes: 1 addition & 1 deletion man/man1/mise.1
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Examples:
$ mise watch build Run `build` tasks repeatedly when files change

$ mise settings Show settings in use
$ mise settings set color 0 Disable color by modifying global config file
$ mise settings color=0 Disable color by modifying global config file
.SH VERSION
v2024.11.23
.SH AUTHORS
Expand Down
13 changes: 12 additions & 1 deletion mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,18 @@ By default, this command modifies `mise.toml` in the current directory."
arg "[ENV_VARS]..." help="Environment variable(s) to set\ne.g.: NODE_ENV=production" var=true
}
cmd "settings" help="Manage settings" {
after_long_help r#"Examples:
# list all settings
$ mise settings

# get the value of the setting "always_keep_download"
$ mise settings always_keep_download

# set the value of the setting "always_keep_download" to "true"
$ mise settings always_keep_download=true
"#
flag "--names" help="Only display key names for each setting"
arg "[SETTING]"
cmd "add" help="Adds a setting to the configuration file" {
long_help r"Adds a setting to the configuration file

Expand Down Expand Up @@ -1045,7 +1056,7 @@ but managed separately with `mise aliases`"
This modifies the contents of ~/.config/mise/config.toml"
after_long_help r"Examples:

$ mise settings set legacy_version_file true
$ mise settings legacy_version_file=true
"
arg "<SETTING>" help="The setting to set"
arg "<VALUE>" help="The value to set"
Expand Down
2 changes: 1 addition & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
$ <bold>mise watch build</bold> Run `build` tasks repeatedly when files change
$ <bold>mise settings</bold> Show settings in use
$ <bold>mise settings set color 0</bold> Disable color by modifying global config file
$ <bold>mise settings color=0</bold> Disable color by modifying global config file
"#
);

Expand Down
39 changes: 34 additions & 5 deletions src/cli/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ mod set;
mod unset;

#[derive(Debug, clap::Args)]
#[clap(about = "Manage settings")]
#[clap(about = "Manage settings", after_long_help = AFTER_LONG_HELP)]
pub struct Settings {
#[clap(subcommand)]
command: Option<Commands>,

/// Only display key names for each setting
#[clap(long, verbatim_doc_comment, alias = "keys")]
names: bool,

#[clap(conflicts_with = "names")]
setting: Option<String>,
}

#[derive(Debug, Subcommand)]
Expand All @@ -41,11 +44,37 @@ impl Commands {

impl Settings {
pub fn run(self) -> Result<()> {
let cmd = self.command.unwrap_or(Commands::Ls(ls::SettingsLs {
key: None,
names: self.names,
}));
let cmd = self.command.unwrap_or_else(|| {
if let Some(setting) = self.setting {
if let Some((setting, value)) = setting.split_once('=') {
Commands::Set(set::SettingsSet {
setting: setting.to_string(),
value: value.to_string(),
})
} else {
Commands::Get(get::SettingsGet { setting })
}
} else {
Commands::Ls(ls::SettingsLs {
key: None,
names: self.names,
})
}
});

cmd.run()
}
}

static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>
# list all settings
$ <bold>mise settings</bold>
# get the value of the setting "always_keep_download"
$ <bold>mise settings always_keep_download</bold>
# set the value of the setting "always_keep_download" to "true"
$ <bold>mise settings always_keep_download=true</bold>
"#
);
2 changes: 1 addition & 1 deletion src/cli/settings/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ fn parse_duration(value: &str) -> Result<toml_edit::Value> {
static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>
$ <bold>mise settings set legacy_version_file true</bold>
$ <bold>mise settings legacy_version_file=true</bold>
"#
);
2 changes: 1 addition & 1 deletion src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl Settings {

pub fn ensure_experimental(&self, what: &str) -> Result<()> {
if !self.experimental {
bail!("{what} is experimental. Enable it with `mise settings set experimental true`");
bail!("{what} is experimental. Enable it with `mise settings experimental=true`");
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/core/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl PythonPlugin {
hint!(
"python_compile",
"To compile python from source, run",
"mise settings set python.compile 1"
"mise settings python.compile=1"
);
}
let arch = python_arch();
Expand All @@ -168,7 +168,7 @@ impl PythonPlugin {
"python_precompiled",
"installing precompiled python from indygreg/python-build-standalone\n\
if you experience issues with this python (e.g.: running poetry), switch to python-build by running",
"mise settings set python.compile 1"
"mise settings python.compile=1"
);
}

Expand Down Expand Up @@ -268,7 +268,7 @@ impl PythonPlugin {
if let Some(virtualenv) = tv.request.options().get("virtualenv") {
if !SETTINGS.experimental {
warn!(
"please enable experimental mode with `mise settings set experimental true` \
"please enable experimental mode with `mise settings experimental=true` \
to use python virtualenv activation"
);
}
Expand Down
8 changes: 8 additions & 0 deletions tasks/fig/src/mise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,14 @@ const completionSpec: Fig.Spec = {
"description": "Only display key names for each setting",
"isRepeatable": false
}
],
"args": [
{
"name": "setting",
"isOptional": true,
"isVariadic": false,
"generators": settingsGenerator
}
]
},
{
Expand Down

0 comments on commit 71d2edf

Please sign in to comment.