Skip to content

Commit

Permalink
Merge branch 'main' into latest-json
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Jan 11, 2025
2 parents 7c975a4 + 80658bc commit e0cfe6f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 18 deletions.
17 changes: 15 additions & 2 deletions docs/cli/config.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `mise config`

- **Usage**: `mise config [--no-header] [-J --json] <SUBCOMMAND>`
- **Usage**: `mise config [FLAGS] <SUBCOMMAND>`
- **Aliases**: `cfg`
- **Source code**: [`src/cli/config/mod.rs`](https://github.com/jdx/mise/blob/main/src/cli/config/mod.rs)

Expand All @@ -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
Expand All @@ -20,5 +24,14 @@ Output in JSON format

- [`mise config generate [-t --tool-versions <TOOL_VERSIONS>] [-o --output <OUTPUT>]`](/cli/config/generate.md)
- [`mise config get [-f --file <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 <FILE>] [-t --type <TYPE>] <KEY> <VALUE>`](/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
```
6 changes: 5 additions & 1 deletion docs/cli/config/ls.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] <SUBCOMMAND>`](/cli/config.md)
- [`mise config [FLAGS] <SUBCOMMAND>`](/cli/config.md)
- [`mise config generate [-t --tool-versions <TOOL_VERSIONS>] [-o --output <OUTPUT>]`](/cli/config/generate.md)
- [`mise config get [-f --file <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 <FILE>] [-t --type <TYPE>] <KEY> <VALUE>`](/cli/config/set.md)
- [`mise deactivate`](/cli/deactivate.md)
- [`mise doctor [-J --json] <SUBCOMMAND>`](/cli/doctor.md)
Expand Down
5 changes: 5 additions & 0 deletions e2e/cli/test_config_ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

assert "mise set FOO=bar"
assert "mise env"
assert "mise cfg --tracked-configs" "$PWD/mise.toml"
3 changes: 3 additions & 0 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" {
Expand Down
19 changes: 17 additions & 2 deletions src/cli/config/ls.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,20 +9,26 @@ 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,
}

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()?;
Expand Down Expand Up @@ -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!(
Expand Down
16 changes: 5 additions & 11 deletions src/cli/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::Subcommand;
use eyre::Result;

pub(crate) mod generate;
mod get;
mod ls;
Expand All @@ -12,19 +13,15 @@ pub struct Config {
#[clap(subcommand)]
command: Option<Commands>,

/// 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),
}
Expand All @@ -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()
}
Expand Down
10 changes: 10 additions & 0 deletions xtasks/fig/src/mise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit e0cfe6f

Please sign in to comment.