From 80658bc6bbd8b7c7a2e14b797502b712d2142cdc Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Sat, 11 Jan 2025 15:34:02 -0600 Subject: [PATCH] feat: added `mise cfg --tracked-configs` (#4059) --- docs/cli/config.md | 17 +++++++++++++++-- docs/cli/config/ls.md | 6 +++++- docs/cli/index.md | 4 ++-- e2e/cli/test_config_ls | 5 +++++ mise.usage.kdl | 3 +++ src/cli/config/ls.rs | 19 +++++++++++++++++-- src/cli/config/mod.rs | 16 +++++----------- xtasks/fig/src/mise.ts | 10 ++++++++++ 8 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 e2e/cli/test_config_ls diff --git a/docs/cli/config.md b/docs/cli/config.md index 48a5613800..d29aa3134e 100644 --- a/docs/cli/config.md +++ b/docs/cli/config.md @@ -1,6 +1,6 @@ # `mise config` -- **Usage**: `mise config [--no-header] [-J --json] ` +- **Usage**: `mise config [FLAGS] ` - **Aliases**: `cfg` - **Source code**: [`src/cli/config/mod.rs`](https://github.com/jdx/mise/blob/main/src/cli/config/mod.rs) @@ -12,6 +12,10 @@ Manage config files Do not print table header +### `--tracked-configs` + +List all tracked config files + ### `-J --json` Output in JSON format @@ -20,5 +24,14 @@ Output in JSON format - [`mise config generate [-t --tool-versions ] [-o --output ]`](/cli/config/generate.md) - [`mise config get [-f --file ] [KEY]`](/cli/config/get.md) -- [`mise config ls [--no-header] [-J --json]`](/cli/config/ls.md) +- [`mise config ls [FLAGS]`](/cli/config/ls.md) - [`mise config set [-f --file ] [-t --type ] `](/cli/config/set.md) + +Examples: + +``` +$ mise config ls +Path Tools +~/.config/mise/config.toml pitchfork +~/src/mise/mise.toml actionlint, bun, cargo-binstall, cargo:cargo-edit, cargo:cargo-insta +``` diff --git a/docs/cli/config/ls.md b/docs/cli/config/ls.md index 3e3975989b..c74c3bbcfa 100644 --- a/docs/cli/config/ls.md +++ b/docs/cli/config/ls.md @@ -1,6 +1,6 @@ # `mise config ls` -- **Usage**: `mise config ls [--no-header] [-J --json]` +- **Usage**: `mise config ls [FLAGS]` - **Aliases**: `list` - **Source code**: [`src/cli/config/ls.rs`](https://github.com/jdx/mise/blob/main/src/cli/config/ls.rs) @@ -12,6 +12,10 @@ List config files currently in use Do not print table header +### `--tracked-configs` + +List all tracked config files + ### `-J --json` Output in JSON format diff --git a/docs/cli/index.md b/docs/cli/index.md index 7638ddd148..c621f99981 100644 --- a/docs/cli/index.md +++ b/docs/cli/index.md @@ -71,10 +71,10 @@ Can also use `MISE_NO_CONFIG=1` - [`mise cache clear [PLUGIN]...`](/cli/cache/clear.md) - [`mise cache prune [--dry-run] [-v --verbose...] [PLUGIN]...`](/cli/cache/prune.md) - [`mise completion [--include-bash-completion-lib] [SHELL]`](/cli/completion.md) -- [`mise config [--no-header] [-J --json] `](/cli/config.md) +- [`mise config [FLAGS] `](/cli/config.md) - [`mise config generate [-t --tool-versions ] [-o --output ]`](/cli/config/generate.md) - [`mise config get [-f --file ] [KEY]`](/cli/config/get.md) -- [`mise config ls [--no-header] [-J --json]`](/cli/config/ls.md) +- [`mise config ls [FLAGS]`](/cli/config/ls.md) - [`mise config set [-f --file ] [-t --type ] `](/cli/config/set.md) - [`mise deactivate`](/cli/deactivate.md) - [`mise doctor [-J --json] `](/cli/doctor.md) diff --git a/e2e/cli/test_config_ls b/e2e/cli/test_config_ls new file mode 100644 index 0000000000..c2d6aac00c --- /dev/null +++ b/e2e/cli/test_config_ls @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +assert "mise set FOO=bar" +assert "mise env" +assert "mise cfg --tracked-configs" "$PWD/mise.toml" diff --git a/mise.usage.kdl b/mise.usage.kdl index a410862b52..eb2d6c5a01 100644 --- a/mise.usage.kdl +++ b/mise.usage.kdl @@ -162,7 +162,9 @@ cmd completion help="Generate shell completions" { cmd config help="Manage config files" { alias cfg alias toml hide=#true + after_long_help "Examples:\n\n $ mise config ls\n Path Tools\n ~/.config/mise/config.toml pitchfork\n ~/src/mise/mise.toml actionlint, bun, cargo-binstall, cargo:cargo-edit, cargo:cargo-insta\n" flag --no-header help="Do not print table header" + flag --tracked-configs help="List all tracked config files" flag "-J --json" help="Output in JSON format" cmd generate help="[experimental] Generate a mise.toml file" { alias g @@ -186,6 +188,7 @@ cmd config help="Manage config files" { alias list after_long_help "Examples:\n\n $ mise config ls\n Path Tools\n ~/.config/mise/config.toml pitchfork\n ~/src/mise/mise.toml actionlint, bun, cargo-binstall, cargo:cargo-edit, cargo:cargo-insta\n" flag --no-header help="Do not print table header" + flag --tracked-configs help="List all tracked config files" flag "-J --json" help="Output in JSON format" } cmd set help="Set the value of a setting in a mise.toml file" { diff --git a/src/cli/config/ls.rs b/src/cli/config/ls.rs index 49953e5daa..10f2662a0b 100644 --- a/src/cli/config/ls.rs +++ b/src/cli/config/ls.rs @@ -1,4 +1,5 @@ use crate::config::config_file::ConfigFile; +use crate::config::tracking::Tracker; use crate::config::Config; use crate::file::display_path; use crate::ui::table::MiseTable; @@ -8,12 +9,16 @@ use itertools::Itertools; /// List config files currently in use #[derive(Debug, clap::Args)] -#[clap(visible_alias="list", verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)] +#[clap(verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)] pub struct ConfigLs { /// Do not print table header #[clap(long, alias = "no-headers", verbatim_doc_comment)] pub no_header: bool, + /// List all tracked config files + #[clap(long, verbatim_doc_comment)] + pub tracked_configs: bool, + /// Output in JSON format #[clap(short = 'J', long, verbatim_doc_comment)] pub json: bool, @@ -21,7 +26,9 @@ pub struct ConfigLs { impl ConfigLs { pub fn run(self) -> Result<()> { - if self.json { + if self.tracked_configs { + self.display_tracked_configs()?; + } else if self.json { self.display_json()?; } else { self.display()?; @@ -79,6 +86,14 @@ impl ConfigLs { miseprintln!("{}", serde_json::to_string_pretty(&array_items)?); Ok(()) } + + fn display_tracked_configs(&self) -> Result<()> { + let tracked_configs = Tracker::list_all()?.into_iter().unique().sorted(); + for path in tracked_configs { + println!("{}", path.display()); + } + Ok(()) + } } static AFTER_LONG_HELP: &str = color_print::cstr!( diff --git a/src/cli/config/mod.rs b/src/cli/config/mod.rs index 115c482668..ee10834c50 100644 --- a/src/cli/config/mod.rs +++ b/src/cli/config/mod.rs @@ -1,5 +1,6 @@ use clap::Subcommand; use eyre::Result; + pub(crate) mod generate; mod get; mod ls; @@ -12,19 +13,15 @@ pub struct Config { #[clap(subcommand)] command: Option, - /// Do not print table header - #[clap(long, alias = "no-headers", verbatim_doc_comment)] - no_header: bool, - - /// Output in JSON format - #[clap(short = 'J', long, verbatim_doc_comment)] - pub json: bool, + #[clap(flatten)] + pub ls: ls::ConfigLs, } #[derive(Debug, Subcommand)] enum Commands { Generate(generate::ConfigGenerate), Get(get::ConfigGet), + #[clap(visible_alias = "list")] Ls(ls::ConfigLs), Set(set::ConfigSet), } @@ -42,10 +39,7 @@ impl Commands { impl Config { pub fn run(self) -> Result<()> { - let cmd = self.command.unwrap_or(Commands::Ls(ls::ConfigLs { - no_header: self.no_header, - json: self.json, - })); + let cmd = self.command.unwrap_or(Commands::Ls(self.ls)); cmd.run() } diff --git a/xtasks/fig/src/mise.ts b/xtasks/fig/src/mise.ts index cb0d0871f9..01d06a6763 100644 --- a/xtasks/fig/src/mise.ts +++ b/xtasks/fig/src/mise.ts @@ -773,6 +773,11 @@ const completionSpec: Fig.Spec = { description: "Do not print table header", isRepeatable: false, }, + { + name: "--tracked-configs", + description: "List all tracked config files", + isRepeatable: false, + }, { name: ["-J", "--json"], description: "Output in JSON format", @@ -827,6 +832,11 @@ const completionSpec: Fig.Spec = { description: "Do not print table header", isRepeatable: false, }, + { + name: "--tracked-configs", + description: "List all tracked config files", + isRepeatable: false, + }, { name: ["-J", "--json"], description: "Output in JSON format",