-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(edit): add --global flag for editing the global config file #9953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # `mise edit --global` writes to the global config file path. | ||
|
|
||
| export MISE_GLOBAL_CONFIG_FILE="$PWD/global-config.toml" | ||
|
|
||
| assert_contains "mise edit --global --dry-run 2>&1" "global-config.toml" | ||
| assert_contains "mise edit -g -n 2>&1" "global-config.toml" | ||
|
|
||
| # A positional path overrides --global regardless of argument order. | ||
| assert_contains "mise edit --global custom.toml --dry-run 2>&1" "custom.toml" | ||
| assert_not_contains "mise edit --global custom.toml --dry-run 2>&1" "global-config.toml" | ||
| assert_contains "mise edit custom.toml --global --dry-run 2>&1" "custom.toml" | ||
| assert_not_contains "mise edit custom.toml --global --dry-run 2>&1" "global-config.toml" | ||
|
|
||
| # Without --global, the default config filename is used (regression guard). | ||
| assert_contains "mise edit --dry-run 2>&1" "mise.toml" | ||
| assert_not_contains "mise edit --dry-run 2>&1" "global-config.toml" | ||
|
|
||
| # --tool-versions merges into the resolved target file, not the local mise.toml. | ||
| cat >preexisting.toml <<EOF | ||
| [tools] | ||
| go = "1.22" | ||
| EOF | ||
| cat >.tool-versions <<EOF | ||
| node 22 | ||
| EOF | ||
| assert_contains "mise edit preexisting.toml --tool-versions .tool-versions --dry-run 2>&1" 'go = "1.22"' | ||
| assert_contains "mise edit preexisting.toml --tool-versions .tool-versions --dry-run 2>&1" 'node = "22"' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,43 @@ | ||
| use std::path::PathBuf; | ||
|
|
||
| use clap::ValueHint; | ||
|
|
||
| use crate::Result; | ||
| use crate::cli::edit; | ||
| use crate::cli::edit::Edit; | ||
|
|
||
| /// Generate a mise.toml file | ||
| #[derive(Debug, clap::Args)] | ||
| #[clap(verbatim_doc_comment, after_long_help = edit::AFTER_LONG_HELP)] | ||
| #[clap(verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)] | ||
| pub struct Config { | ||
| #[clap(flatten)] | ||
| edit: edit::Edit, | ||
| /// Generate the global config file (~/.config/mise/config.toml) | ||
| #[clap(long, short = 'g')] | ||
| global: bool, | ||
| /// Show what would be generated without writing to file | ||
| #[clap(long, short = 'n')] | ||
| dry_run: bool, | ||
| /// Path to the config file to create | ||
| #[clap(verbatim_doc_comment, value_hint = ValueHint::FilePath)] | ||
| path: Option<PathBuf>, | ||
| /// Path to a .tool-versions file to import tools from | ||
| #[clap(long, short, verbatim_doc_comment, value_hint = ValueHint::FilePath)] | ||
| tool_versions: Option<PathBuf>, | ||
| } | ||
|
|
||
| impl Config { | ||
| pub async fn run(self) -> Result<()> { | ||
| self.edit.run().await | ||
| Edit::new(self.global, self.dry_run, self.path, self.tool_versions) | ||
| .run() | ||
| .await | ||
| } | ||
| } | ||
|
|
||
| static AFTER_LONG_HELP: &str = color_print::cstr!( | ||
| r#"<bold><underline>Examples:</underline></bold> | ||
|
|
||
| $ <bold>mise generate config</bold> <dim># generate mise.toml interactively</dim> | ||
| $ <bold>mise generate config .mise.toml</bold> <dim># generate a specific file</dim> | ||
| $ <bold>mise generate config -g</bold> <dim># generate the global config file</dim> | ||
| $ <bold>mise generate config -y</bold> <dim># skip interactive editor</dim> | ||
| $ <bold>mise generate config -n</bold> <dim># preview without writing</dim> | ||
| "# | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
pathresolution logic can be simplified by avoiding theclone()onself.path, asselfis consumed by therunmethod.Note: The
pathvariable determined here should also be passed toself.tool_versions()(at line 160, though not visible in this diff hunk) to ensure that tool versions are imported into the correct file when using--globalor an explicit path. Currently,tool_versions()(at line 259) hardcodes the target path tomise.toml, which would cause incorrect behavior when targeting the global config (it would read the local config, merge versions, and then write that result to the global path).