From ad8b13d292b6c0664841eab9feeb88289f3aca5e Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Sun, 2 Aug 2026 13:18:29 +0900 Subject: [PATCH] feat(config): accept --file wherever `--path` names a config to write --- e2e/cli/test_config_target_aliases | 16 +++++++++ man/man1/mise.1 | 10 +++--- mise.usage.kdl | 12 +++---- src/cli/dotfiles/add.rs | 2 +- src/cli/mod.rs | 57 ++++++++++++++++++++++++++++++ src/cli/system/brew/tap.rs | 8 ++++- src/cli/system/brew/untap.rs | 8 ++++- src/cli/system/import.rs | 8 ++++- src/cli/system/use.rs | 8 ++++- 9 files changed, 113 insertions(+), 16 deletions(-) diff --git a/e2e/cli/test_config_target_aliases b/e2e/cli/test_config_target_aliases index 48816e6fb84..2d2086290b7 100644 --- a/e2e/cli/test_config_target_aliases +++ b/e2e/cli/test_config_target_aliases @@ -54,3 +54,19 @@ mise unuse --no-prune --file subdir dummy@1 assert_not_contains "cat subdir/mise.toml" "dummy" mise unset --path subdir SUBDIR_VAR assert_not_contains "cat subdir/mise.toml" "SUBDIR_VAR" + +# the commands that write to a config under `--path` take --file too. `brew tap`/`untap` only +# edit `[bootstrap.brew.taps]` — they do not touch a Homebrew installation — so they are the +# cheap way to exercise this end to end; the rest are covered by the clap assertions in +# src/cli/mod.rs, since running them installs or applies something. +mise bootstrap packages brew tap acme/tools --file tap-alias.toml +assert_contains "cat tap-alias.toml" "acme/tools" + +mise bootstrap packages brew untap acme/tools --file tap-alias.toml +assert_not_contains "cat tap-alias.toml" "acme/tools" + +# and the canonical name is unaffected +mise bootstrap packages brew tap acme/tools --path tap-alias.toml +assert_contains "cat tap-alias.toml" "acme/tools" +mise bootstrap packages brew untap acme/tools --path tap-alias.toml +assert_not_contains "cat tap-alias.toml" "acme/tools" diff --git a/man/man1/mise.1 b/man/man1/mise.1 index 78acd9913ae..71142c7be97 100644 --- a/man/man1/mise.1 +++ b/man/man1/mise.1 @@ -947,7 +947,7 @@ Print the config/source updates without writing anything \fB\-\-no\-apply\fR Add the entry without applying it .TP -\fB\-p, \-\-path\fR \fI\fR +\fB\-p, \-\-path, \-\-file\fR \fI\fR Write to this config file or directory .TP \fB\-s, \-\-source\fR \fI\fR @@ -1189,7 +1189,7 @@ Write to the local config instead of the global config \fB\-n, \-\-dry\-run\fR Print the config change without writing it .TP -\fB\-p, \-\-path\fR \fI\fR +\fB\-p, \-\-path, \-\-file\fR \fI\fR Write to this config file or directory \fBArguments:\fR .PP @@ -1213,7 +1213,7 @@ Write to the local config instead of the global config \fB\-n, \-\-dry\-run\fR Print the config change without writing it .TP -\fB\-p, \-\-path\fR \fI\fR +\fB\-p, \-\-path, \-\-file\fR \fI\fR Write to this config file or directory \fBArguments:\fR .PP @@ -1250,7 +1250,7 @@ Import every linked formula, including dependencies \fB\-n, \-\-dry\-run\fR Print the config change without writing config .TP -\fB\-p, \-\-path\fR \fI\fR +\fB\-p, \-\-path, \-\-file\fR \fI\fR Write to this config file or directory .SH "MISE BOOTSTRAP PACKAGES PRUNE" Prune installed system packages no longer declared in `[bootstrap.packages]` @@ -1346,7 +1346,7 @@ Write to the global config (~/.config/mise/config.toml) instead of the local one \fB\-n, \-\-dry\-run\fR Print the commands that would run without writing config or installing .TP -\fB\-p, \-\-path\fR \fI\fR +\fB\-p, \-\-path, \-\-file\fR \fI\fR Write to this config file or directory .TP \fB\-y, \-\-yes\fR diff --git a/mise.usage.kdl b/mise.usage.kdl index e4df3a8ad64..38cf7db7bad 100644 --- a/mise.usage.kdl +++ b/mise.usage.kdl @@ -391,7 +391,7 @@ Examples: } flag "-n --dry-run" help="Print the config/source updates without writing anything" flag --no-apply help="Add the entry without applying it" - flag "-p --path" help="Write to this config file or directory" { + flag "-p --path --file" help="Write to this config file or directory" { arg } flag "-s --source" help="Source path to use for a single target" { @@ -598,7 +598,7 @@ Examples: """# flag "-l --local" help="Write to the local config instead of the global config" flag "-n --dry-run" help="Print the config change without writing it" - flag "-p --path" help="Write to this config file or directory" { + flag "-p --path --file" help="Write to this config file or directory" { arg } arg help="Tap name, e.g. `owner/repo`" @@ -614,7 +614,7 @@ Examples: """# flag "-l --local" help="Write to the local config instead of the global config" flag "-n --dry-run" help="Print the config change without writing it" - flag "-p --path" help="Write to this config file or directory" { + flag "-p --path --file" help="Write to this config file or directory" { arg } arg … help="Tap name(s), e.g. `owner/repo`" var=#true @@ -648,7 +648,7 @@ Examples: } flag --all help="Import every linked formula, including dependencies" flag "-n --dry-run" help="Print the config change without writing config" - flag "-p --path" help="Write to this config file or directory" { + flag "-p --path --file" help="Write to this config file or directory" { arg } } @@ -750,7 +750,7 @@ Examples: } flag "-g --global" help="Write to the global config (~/.config/mise/config.toml) instead of the local one" flag "-n --dry-run" help="Print the commands that would run without writing config or installing" - flag "-p --path" help="Write to this config file or directory" { + flag "-p --path --file" help="Write to this config file or directory" { arg } flag "-y --yes" help="Skip the confirmation prompt" @@ -1075,7 +1075,7 @@ Examples: } flag "-n --dry-run" help="Print the config/source updates without writing anything" flag --no-apply help="Add the entry without applying it" - flag "-p --path" help="Write to this config file or directory" { + flag "-p --path --file" help="Write to this config file or directory" { arg } flag "-s --source" help="Source path to use for a single target" { diff --git a/src/cli/dotfiles/add.rs b/src/cli/dotfiles/add.rs index eac13768c18..4a945eac6f0 100644 --- a/src/cli/dotfiles/add.rs +++ b/src/cli/dotfiles/add.rs @@ -50,7 +50,7 @@ pub struct DotfilesAdd { pub(super) no_apply: bool, /// Write to this config file or directory - #[clap(long, short, value_name = "PATH", conflicts_with_all = ["global", "local"])] + #[clap(long, short, visible_alias = "file", value_name = "PATH", conflicts_with_all = ["global", "local"])] pub(super) path: Option, /// Source path to use for a single target diff --git a/src/cli/mod.rs b/src/cli/mod.rs index e0f5cca1ddb..ebbb9825937 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -985,6 +985,63 @@ mod tests { } } + /// Commands that name a config file to write to accept both spellings, so it + /// does not matter which one you remember. See + /// . + /// + /// Asserted through clap rather than end-to-end because several of these + /// commands install or apply something when actually run. + #[test] + fn test_config_target_options_accept_both_names() { + // (command path, argument id, expected alias, available on this platform) + let cases: &[(&[&str], &str, &str, bool)] = &[ + (&["use"], "path", "file", true), + (&["unuse"], "path", "file", true), + (&["set"], "file", "path", true), + (&["unset"], "file", "path", true), + (&["dotfiles", "add"], "path", "file", true), + (&["bootstrap", "packages", "use"], "path", "file", true), + (&["bootstrap", "packages", "import"], "path", "file", true), + // the brew manager is not registered on Windows + ( + &["bootstrap", "packages", "brew", "tap"], + "path", + "file", + cfg!(not(windows)), + ), + ( + &["bootstrap", "packages", "brew", "untap"], + "path", + "file", + cfg!(not(windows)), + ), + ]; + let root = Cli::command(); + + for (path, arg_name, alias, available) in cases { + if !available { + continue; + } + let command = path.iter().fold(&root, |command, name| { + command + .get_subcommands() + .find(|subcommand| subcommand.get_name() == *name) + .unwrap_or_else(|| panic!("missing command path {}", path.join(" "))) + }); + let arg = command + .get_arguments() + .find(|arg| arg.get_id() == *arg_name) + .unwrap_or_else(|| panic!("missing --{arg_name} on {}", path.join(" "))); + + assert!( + arg.get_visible_aliases() + .is_some_and(|aliases| aliases.contains(alias)), + "missing visible --{alias} alias for --{arg_name} on {}", + path.join(" ") + ); + } + } + #[test] fn test_escape_task_args_preserves_task_separator_tail() { let cmd = Cli::command(); diff --git a/src/cli/system/brew/tap.rs b/src/cli/system/brew/tap.rs index 86ba6b4663b..5dd0d8757a8 100644 --- a/src/cli/system/brew/tap.rs +++ b/src/cli/system/brew/tap.rs @@ -28,7 +28,13 @@ pub struct SystemBrewTap { dry_run: bool, /// Write to this config file or directory - #[clap(long, short, value_name = "PATH", conflicts_with = "local")] + #[clap( + long, + short, + visible_alias = "file", + value_name = "PATH", + conflicts_with = "local" + )] path: Option, } diff --git a/src/cli/system/brew/untap.rs b/src/cli/system/brew/untap.rs index ab38d48e15f..276b4d7e133 100644 --- a/src/cli/system/brew/untap.rs +++ b/src/cli/system/brew/untap.rs @@ -24,7 +24,13 @@ pub struct SystemBrewUntap { dry_run: bool, /// Write to this config file or directory - #[clap(long, short, value_name = "PATH", conflicts_with = "local")] + #[clap( + long, + short, + visible_alias = "file", + value_name = "PATH", + conflicts_with = "local" + )] path: Option, } diff --git a/src/cli/system/import.rs b/src/cli/system/import.rs index 7ee9b692156..37f79b6392a 100644 --- a/src/cli/system/import.rs +++ b/src/cli/system/import.rs @@ -53,7 +53,13 @@ pub struct SystemImport { dry_run: bool, /// Write to this config file or directory - #[clap(long, short, value_name = "PATH", conflicts_with = "global")] + #[clap( + long, + short, + visible_alias = "file", + value_name = "PATH", + conflicts_with = "global" + )] path: Option, } diff --git a/src/cli/system/use.rs b/src/cli/system/use.rs index 59ca3ebd650..376a3d6806f 100644 --- a/src/cli/system/use.rs +++ b/src/cli/system/use.rs @@ -43,7 +43,13 @@ pub struct SystemUse { dry_run: bool, /// Write to this config file or directory - #[clap(long, short, value_name = "PATH", conflicts_with = "global")] + #[clap( + long, + short, + visible_alias = "file", + value_name = "PATH", + conflicts_with = "global" + )] path: Option, /// Skip the confirmation prompt