Skip to content

Commit

Permalink
feat: added completions to more commands (#3910)
Browse files Browse the repository at this point in the history
Fixes #3909
  • Loading branch information
jdx authored Jan 1, 2025
1 parent a31cd43 commit 0cfaf74
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 105 deletions.
10 changes: 5 additions & 5 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Can also use `MISE_NO_CONFIG=1`
- [`mise install-into <TOOL@VERSION> <PATH>`](/cli/install-into.md)
- [`mise latest [-i --installed] <TOOL@VERSION>`](/cli/latest.md)
- [`mise link [-f --force] <TOOL@VERSION> <PATH>`](/cli/link.md)
- [`mise ls [FLAGS] [PLUGIN]...`](/cli/ls.md)
- [`mise ls [FLAGS] [INSTALLED_TOOL]...`](/cli/ls.md)
- [`mise ls-remote [--all] [TOOL@VERSION] [PREFIX]`](/cli/ls-remote.md)
- [`mise outdated [FLAGS] [TOOL@VERSION]...`](/cli/outdated.md)
- [`mise plugins [FLAGS] <SUBCOMMAND>`](/cli/plugins.md)
Expand All @@ -110,7 +110,7 @@ Can also use `MISE_NO_CONFIG=1`
- [`mise reshim [-f --force]`](/cli/reshim.md)
- [`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 set [--file <FILE>] [-g --global] [ENV_VAR]...`](/cli/set.md)
- [`mise settings [FLAGS] [SETTING] [VALUE] <SUBCOMMAND>`](/cli/settings.md)
- [`mise settings add [-l --local] <SETTING> <VALUE>`](/cli/settings/add.md)
- [`mise settings get [-l --local] <SETTING>`](/cli/settings/get.md)
Expand All @@ -129,14 +129,14 @@ Can also use `MISE_NO_CONFIG=1`
- [`mise tasks info [-J --json] <TASK>`](/cli/tasks/info.md)
- [`mise tasks ls [FLAGS]`](/cli/tasks/ls.md)
- [`mise tasks run [FLAGS] [TASK] [ARGS]...`](/cli/tasks/run.md)
- [`mise tool [FLAGS] <BACKEND>`](/cli/tool.md)
- [`mise tool [FLAGS] <TOOL>`](/cli/tool.md)
- [`mise trust [FLAGS] [CONFIG_FILE]`](/cli/trust.md)
- [`mise uninstall [-a --all] [-n --dry-run] [INSTALLED_TOOL@VERSION]...`](/cli/uninstall.md)
- [`mise unset [-f --file <FILE>] [-g --global] [KEYS]...`](/cli/unset.md)
- [`mise unset [-f --file <FILE>] [-g --global] [ENV_KEY]...`](/cli/unset.md)
- [`mise unuse [--no-prune] [--global] <INSTALLED_TOOL@VERSION>...`](/cli/unuse.md)
- [`mise upgrade [FLAGS] [TOOL@VERSION]...`](/cli/upgrade.md)
- [`mise use [FLAGS] [TOOL@VERSION]...`](/cli/use.md)
- [`mise version`](/cli/version.md)
- [`mise watch [FLAGS] [TASK] [ARGS]...`](/cli/watch.md)
- [`mise where <TOOL@VERSION>`](/cli/where.md)
- [`mise which [FLAGS] <BIN_NAME>`](/cli/which.md)
- [`mise which [FLAGS] [BIN_NAME]`](/cli/which.md)
6 changes: 3 additions & 3 deletions docs/cli/ls.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `mise ls`

- **Usage**: `mise ls [FLAGS] [PLUGIN]...`
- **Usage**: `mise ls [FLAGS] [INSTALLED_TOOL]...`
- **Aliases**: `list`
- **Source code**: [`src/cli/ls.rs`](https://github.com/jdx/mise/blob/main/src/cli/ls.rs)

Expand All @@ -14,9 +14,9 @@ It's a useful command to get the current state of your tools.

## Arguments

### `[PLUGIN]...`
### `[INSTALLED_TOOL]...`

Only show tool versions from [PLUGIN]
Only show tool versions from [TOOL]

## Flags

Expand Down
4 changes: 2 additions & 2 deletions docs/cli/set.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `mise set`

- **Usage**: `mise set [--file <FILE>] [-g --global] [ENV_VARS]...`
- **Usage**: `mise set [--file <FILE>] [-g --global] [ENV_VAR]...`
- **Source code**: [`src/cli/set.rs`](https://github.com/jdx/mise/blob/main/src/cli/set.rs)

Set environment variables in mise.toml
Expand All @@ -9,7 +9,7 @@ By default, this command modifies `mise.toml` in the current directory.

## Arguments

### `[ENV_VARS]...`
### `[ENV_VAR]...`

Environment variable(s) to set
e.g.: NODE_ENV=production
Expand Down
4 changes: 2 additions & 2 deletions docs/cli/tool.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# `mise tool`

- **Usage**: `mise tool [FLAGS] <BACKEND>`
- **Usage**: `mise tool [FLAGS] <TOOL>`
- **Source code**: [`src/cli/tool.rs`](https://github.com/jdx/mise/blob/main/src/cli/tool.rs)

Gets information about a tool

## Arguments

### `<BACKEND>`
### `<TOOL>`

Tool name to get information about

Expand Down
4 changes: 2 additions & 2 deletions docs/cli/unset.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `mise unset`

- **Usage**: `mise unset [-f --file <FILE>] [-g --global] [KEYS]...`
- **Usage**: `mise unset [-f --file <FILE>] [-g --global] [ENV_KEY]...`
- **Source code**: [`src/cli/unset.rs`](https://github.com/jdx/mise/blob/main/src/cli/unset.rs)

Remove environment variable(s) from the config file.
Expand All @@ -9,7 +9,7 @@ By default, this command modifies `mise.toml` in the current directory.

## Arguments

### `[KEYS]...`
### `[ENV_KEY]...`

Environment variable(s) to remove
e.g.: NODE_ENV
Expand Down
4 changes: 2 additions & 2 deletions docs/cli/which.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `mise which`

- **Usage**: `mise which [FLAGS] <BIN_NAME>`
- **Usage**: `mise which [FLAGS] [BIN_NAME]`
- **Source code**: [`src/cli/which.rs`](https://github.com/jdx/mise/blob/main/src/cli/which.rs)

Shows the path that a tool's bin points to.
Expand All @@ -9,7 +9,7 @@ Use this to figure out what version of a tool is currently active.

## Arguments

### `<BIN_NAME>`
### `[BIN_NAME]`

The bin to look up

Expand Down
2 changes: 1 addition & 1 deletion e2e/cli/test_registry
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

assert "mise registry gh" "aqua:cli/cli ubi:cli/cli[exe=gh] asdf:bartlomiejdanek/asdf-github-cli"
assert_contains "mise registry" "gh aqua:cli/cli ubi:cli/cli[exe=gh] asdf:bartlomiejdanek/asdf-github-cli"
assert_contains "mise registry" "gh aqua:cli/cli ubi:cli/cli[exe=gh] asdf:bartlomiejdanek/asdf-github-cli"
8 changes: 2 additions & 6 deletions mise.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
[tools.actionlint]
version = "1.7.4"
version = "1.7.5"
backend = "aqua:rhysd/actionlint"

[tools.actionlint.checksums]
actionlint-linux-x86_64 = "sha256:39cae525cdb54af5d91dcf27f55e040d37ecea01dd4153490c4dc84f5d251d46"
actionlint-macos-aarch64 = "sha256:f381afca13b39e095e4cee25e2b2abbb39ae8b2848f5ccd2564bf86192c1b661"
"actionlint.exe-windows-x86_64" = "sha256:04ca117d9f33b77731fd3ef6a3670bd6b11b40c1b1cc5b7aaf6c28392d74d2e2"
"actionlint_1.7.4_linux_amd64.tar.gz" = "sha256:fc0a6886bbb9a23a39eeec4b176193cadb54ddbe77cdbb19b637933919545395"
"actionlint_1.7.4_linux_arm64.tar.gz" = "sha256:ede03682dc955381d057dde95bb85ce9ca418122209a8a313b617d4adec56416"
"actionlint_1.7.5_darwin_arm64.tar.gz" = "sha256:397119f9baa3fd9fe195db340b30acdaea532826e19a047a9cc9d96add7c267d"

[tools.bun]
version = "1.1.42"
Expand Down
25 changes: 17 additions & 8 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ It's a useful command to get the current state of your tools."#
}
"#
flag "-p --plugin" hide=true {
arg "<PLUGIN_FLAG>"
arg "<TOOL_FLAG>"
}
flag "-c --current" help="Only show tool versions currently specified in a mise.toml"
flag "-g --global" help="Only show tool versions currently specified in the global mise.toml"
Expand All @@ -817,7 +817,7 @@ It's a useful command to get the current state of your tools."#
arg "<PREFIX>"
}
flag "--no-header" help="Don't display headers"
arg "[PLUGIN]..." help="Only show tool versions from [PLUGIN]" required=false var=true
arg "[INSTALLED_TOOL]..." help="Only show tool versions from [TOOL]" required=false var=true
}
cmd "ls-remote" help="List runtime versions available for install." {
alias "list-all" "list-remote" hide=true
Expand Down Expand Up @@ -1025,6 +1025,7 @@ For example, `poetry` is shorthand for `asdf:mise-plugins/mise-poetry`."
flag "-b --backend" help="Show only tools for this backend" {
arg "<BACKEND>"
}
flag "--complete" help="Print all tools with descriptions for shell completions" hide=true
flag "--hide-aliased" help="Hide aliased tools"
arg "[NAME]" help="Show only the specified tool's full name" required=false
}
Expand Down Expand Up @@ -1169,12 +1170,13 @@ By default, this command modifies `mise.toml` in the current directory."
long_help "The TOML file to update\n\nDefaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or `mise.toml`."
arg "<FILE>"
}
flag "--complete" help="Render completions" hide=true
flag "-g --global" help="Set the environment variable in the global config file"
flag "--remove" help="Remove the environment variable from config file" var=true hide=true {
flag "--remove --rm --unset" help="Remove the environment variable from config file" var=true hide=true {
long_help "Remove the environment variable from config file\n\nCan be used multiple times."
arg "<ENV_VAR>"
arg "<ENV_KEY>"
}
arg "[ENV_VARS]..." help="Environment variable(s) to set\ne.g.: NODE_ENV=production" required=false var=true
arg "[ENV_VAR]..." help="Environment variable(s) to set\ne.g.: NODE_ENV=production" required=false var=true
}
cmd "settings" help="Manage settings" {
long_help r"Show current settings
Expand Down Expand Up @@ -1624,7 +1626,7 @@ cmd "tool" help="Gets information about a tool" {
flag "--requested" help="Only show requested versions"
flag "--config-source" help="Only show config source"
flag "--tool-options" help="Only show tool options"
arg "<BACKEND>" help="Tool name to get information about"
arg "<TOOL>" help="Tool name to get information about"
}
cmd "trust" help="Marks a config file as trusted" {
long_help r"Marks a config file as trusted
Expand Down Expand Up @@ -1685,7 +1687,7 @@ By default, this command modifies `mise.toml` in the current directory."
arg "<FILE>"
}
flag "-g --global" help="Use the global config file"
arg "[KEYS]..." help="Environment variable(s) to remove\ne.g.: NODE_ENV" required=false var=true
arg "[ENV_KEY]..." help="Environment variable(s) to remove\ne.g.: NODE_ENV" required=false var=true
}
cmd "unuse" help="Removes installed tool versions from mise.toml" {
alias "rm" "remove"
Expand Down Expand Up @@ -2052,12 +2054,13 @@ Use this to figure out what version of a tool is currently active."
$ mise which node --version
20.0.0
"
flag "--complete" hide=true
flag "--plugin" help="Show the plugin name instead of the path"
flag "--version" help="Show the version instead of the path"
flag "-t --tool" help="Use a specific tool@version\ne.g.: `mise which npm --tool=node@20`" {
arg "<TOOL@VERSION>"
}
arg "<BIN_NAME>" help="The bin to look up"
arg "[BIN_NAME]" help="The bin to look up" required=false
}
cmd "render-help" hide=true help="internal command to generate markdown from help"
cmd "render-mangen" hide=true help="internal command to generate markdown from help"
Expand All @@ -2066,10 +2069,16 @@ source_code_link_template "https://github.com/jdx/mise/blob/main/src/cli/{{path}
complete "alias" run="mise alias ls {{words[PREV]}} | awk '{print $2}'"
complete "config_file" type="file"
complete "new_plugin" run="mise plugins --all"
complete "installed_tool" run="mise plugins --core --user"
complete "plugin" run="mise plugins --core --user"
complete "prefix" run="mise ls-remote {{words[PREV]}}"
complete "setting" run="mise settings --complete" descriptions=true
complete "task" run="mise tasks ls --complete" descriptions=true
complete "tool" run="mise registry --complete" descriptions=true
complete "env_var" run=r#"mise set --complete | awk '{print $1"="}'"#
complete "env_key" run="mise set --complete"
complete "backend" run="mise backends"
complete "bin_name" run="mise which --complete"

complete "tool@version" run=r#"
cur="{{words[CURRENT]}}"
Expand Down
6 changes: 6 additions & 0 deletions src/assets/mise-extra.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ source_code_link_template "https://github.com/jdx/mise/blob/main/src/cli/{{path}
complete "alias" run="mise alias ls {{words[PREV]}} | awk '{print $2}'"
complete "config_file" type="file"
complete "new_plugin" run="mise plugins --all"
complete "installed_tool" run="mise plugins --core --user"
complete "plugin" run="mise plugins --core --user"
complete "prefix" run="mise ls-remote {{words[PREV]}}"
complete "setting" run="mise settings --complete" descriptions=true
complete "task" run="mise tasks ls --complete" descriptions=true
complete "tool" run="mise registry --complete" descriptions=true
complete "env_var" run=r#"mise set --complete | awk '{print $1"="}'"#
complete "env_key" run="mise set --complete"
complete "backend" run="mise backends"
complete "bin_name" run="mise which --complete"

complete "tool@version" run=r#"
cur="{{words[CURRENT]}}"
Expand Down
26 changes: 13 additions & 13 deletions src/cli/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use crate::ui::table::MiseTable;
#[derive(Debug, clap::Args)]
#[clap(visible_alias = "list", verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)]
pub struct Ls {
/// Only show tool versions from [PLUGIN]
#[clap(conflicts_with = "plugin_flag")]
plugin: Option<Vec<BackendArg>>,
/// Only show tool versions from [TOOL]
#[clap(conflicts_with = "tool_flag")]
installed_tool: Option<Vec<BackendArg>>,

#[clap(long = "plugin", short, hide = true)]
plugin_flag: Option<BackendArg>,
#[clap(long = "plugin", short = 'p', hide = true)]
tool_flag: Option<BackendArg>,

/// Only show tool versions currently specified in a mise.toml
#[clap(long, short)]
Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct Ls {
missing: bool,

/// Display versions matching this prefix
#[clap(long, requires = "plugin")]
#[clap(long, requires = "installed_tool")]
prefix: Option<String>,

/// Don't display headers
Expand All @@ -73,9 +73,9 @@ pub struct Ls {
impl Ls {
pub fn run(mut self) -> Result<()> {
let config = Config::try_get()?;
self.plugin = self
.plugin
.or_else(|| self.plugin_flag.clone().map(|p| vec![p]));
self.installed_tool = self
.installed_tool
.or_else(|| self.tool_flag.clone().map(|p| vec![p]));
self.verify_plugin()?;

let mut runtimes = self.get_runtime_list(&config)?;
Expand All @@ -101,7 +101,7 @@ impl Ls {
}

fn verify_plugin(&self) -> Result<()> {
if let Some(plugins) = &self.plugin {
if let Some(plugins) = &self.installed_tool {
for ba in plugins {
if let Some(plugin) = ba.backend()?.plugin() {
ensure!(plugin.is_installed(), "{ba} is not installed");
Expand All @@ -112,7 +112,7 @@ impl Ls {
}

fn display_json(&self, runtimes: Vec<RuntimeRow>) -> Result<()> {
if let Some(plugins) = &self.plugin {
if let Some(plugins) = &self.installed_tool {
// only runtimes for 1 plugin
let runtimes: Vec<JSONToolVersion> = runtimes
.into_iter()
Expand Down Expand Up @@ -185,7 +185,7 @@ impl Ls {
.list_all_versions()?
.into_iter()
.map(|(b, tv)| ((b, tv.version.clone()), tv))
.filter(|((b, _), _)| match &self.plugin {
.filter(|((b, _), _)| match &self.installed_tool {
Some(p) => p.contains(b.ba()),
None => true,
})
Expand All @@ -199,7 +199,7 @@ impl Ls {
.map(|(k, tv)| (self, k.0, tv.clone(), tv.request.source().clone()))
// if it isn't installed and it's not specified, don't show it
.filter(|(_ls, p, tv, source)| !source.is_unknown() || p.is_version_installed(tv, true))
.filter(|(_ls, p, _, _)| match &self.plugin {
.filter(|(_ls, p, _, _)| match &self.installed_tool {
Some(backend) => backend.contains(p.ba()),
None => true,
})
Expand Down
Loading

0 comments on commit 0cfaf74

Please sign in to comment.