-
-
Notifications
You must be signed in to change notification settings - Fork 769
fix(cli): handle mise help without requiring tasks
#6961
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Test that `mise help` works even when no tasks are defined | ||
| # This validates the fix for https://github.com/jdx/mise/discussions/6947 | ||
|
|
||
| echo "Testing 'mise help' command without tasks defined..." | ||
|
|
||
| # Test in a temporary directory without any mise config | ||
| TEMP_DIR=$(mktemp -d) | ||
| cd "$TEMP_DIR" | ||
|
|
||
| # Test 1: `mise help` should work without tasks | ||
| echo "Test 1: mise help (without tasks)" | ||
| assert_contains "mise help" "Usage: mise" | ||
|
|
||
| # Test 2: `mise --help` should work (baseline) | ||
| echo "Test 2: mise --help" | ||
| assert_contains "mise --help" "Usage: mise" | ||
|
|
||
| # Test 3: `mise -h` should work (baseline) | ||
| echo "Test 3: mise -h" | ||
| assert_contains "mise -h" "Usage: mise" | ||
|
|
||
| # Test 4: All three should produce similar output | ||
| echo "Test 4: Verify all help variants work consistently" | ||
| if mise help >/dev/null 2>&1; then | ||
| ok "mise help succeeded" | ||
| else | ||
| fail "mise help failed" | ||
| fi | ||
| if mise --help >/dev/null 2>&1; then | ||
| ok "mise --help succeeded" | ||
| else | ||
| fail "mise --help failed" | ||
| fi | ||
| if mise -h >/dev/null 2>&1; then | ||
| ok "mise -h succeeded" | ||
| else | ||
| fail "mise -h failed" | ||
| fi | ||
|
|
||
| # Cleanup | ||
| cd - >/dev/null | ||
| rm -rf "$TEMP_DIR" | ||
|
|
||
| echo "" | ||
| echo "All help command tests passed!" | ||
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -413,6 +413,11 @@ fn preprocess_args_for_naked_run(cmd: &clap::Command, args: &[String]) -> Vec<St | |||||||||
| return args.to_vec(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Special case: "help" should print help, not be treated as a task | ||||||||||
| if args[i] == "help" || args[i] == "-h" || args[i] == "--help" { | ||||||||||
| return args.to_vec(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // This is a naked run - inject "run" subcommand so clap routes it correctly | ||||||||||
| // Format: ["mise", "-q", "task", "arg1"] becomes ["mise", "-q", "run", "task", "arg1"] | ||||||||||
| // This preserves global flags while making it an explicit run command | ||||||||||
|
|
@@ -467,6 +472,12 @@ impl Cli { | |||||||||
| Ok(cmd) | ||||||||||
| } else { | ||||||||||
| if let Some(task) = self.task { | ||||||||||
| // Handle special case: "help", "-h", or "--help" as task should print help | ||||||||||
| if task == "help" || task == "-h" || task == "--help" { | ||||||||||
|
Comment on lines
+475
to
+476
|
||||||||||
| // Handle special case: "help", "-h", or "--help" as task should print help | |
| if task == "help" || task == "-h" || task == "--help" { | |
| // Handle special case: "help" as task should print help | |
| if task == "help" { |
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 cleanup section uses 'cd -' which assumes the previous directory is still in the directory stack. If the script fails before reaching cleanup, the temp directory won't be removed. Consider using a trap to ensure cleanup on exit:
trap 'rm -rf \"$TEMP_DIR\"' EXIT