#!/usr/bin/env bash

cat <<EOF >mise.toml
[tasks.atask]
run = 'echo {{arg(name="myarg")}}'
[tasks.npm]
run = 'echo npm'
EOF

assert "mise run atask --help 2>&1 || true" "Usage: atask <myarg>

Arguments:
  <myarg>"

assert_contains "mise --help 2>&1 || true" "Usage: mise [OPTIONS] [TASK] [COMMAND]"
assert_contains "mise install --help 2>&1 || true" "Usage: mise install [OPTIONS] [TOOL@VERSION]..."
assert_contains "mise run --help 2>&1 || true" "Usage: run [OPTIONS] [TASK] [ARGS]..."
# `-- --help` now bypasses the usage parser so --help reaches the script
# (see https://github.com/jdx/mise/discussions/5460). The task's required
# arg renders empty in this case because the parser is skipped entirely.
assert "mise atask -q -- --help 2>&1 || true" "--help"
# If task has no usage defined, --help shows task info
assert_contains "mise run npm --help 2>&1 || true" "Task: npm"
# With --, --help is passed to the task script
assert "mise -q npm -- --help 2>&1 || true" "npm --help"
assert "mise atask -q -- -- --help 2>&1 || true" "-- --help"
assert "mise run atask -q -- --help 2>&1 || true" "--help"
assert "mise run atask -q -- foo --help 2>&1 || true" "foo --help"
assert "mise atask -q -- foo --help 2>&1 || true" "foo --help"
# Without `--`, --help (with or without extra args) still shows mise's task help
assert_contains "mise run atask -q foo --help 2>&1 || true" "Usage: atask <myarg>"
assert_contains "mise atask -q foo --help 2>&1 || true" "Usage: atask <myarg>"
