Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions e2e/cli/test_help_without_tasks
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"
Comment on lines +11 to +12
Copy link

Copilot AI Nov 12, 2025

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

Copilot uses AI. Check for mistakes.

# 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!"
11 changes: 11 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition checks if task equals '-h' or '--help', but these flags would have been parsed by clap as CLI flags, not as task names. Only 'help' can reach this point as a task value. The additional checks for '-h' and '--help' are unreachable and should be removed.

Suggested change
// 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" {

Copilot uses AI. Check for mistakes.
Cli::command().print_help()?;
exit(0);
}

let config = Config::get().await?;

// Expand :task pattern to match tasks in current directory's config root
Expand Down
Loading