#!/usr/bin/env bash

# Create a subdirectory with a task
mkdir -p subdir
cat <<EOF >subdir/mise.toml
[tasks.build]
run = 'echo "Building project"'
description = 'Build the project'
EOF

# For tasks WITHOUT usage spec, --help shows task info instead of executing
assert_contains "mise run --cd subdir build --help 2>&1 || true" "Task: build"
assert_contains "mise run --cd subdir build --help 2>&1 || true" "Description: Build the project"

# -- separator still passes --help through to the task
assert "mise run --cd subdir build -- --help 2>&1 || true" "[build] $ echo \"Building project\" --help
Building project --help"

# Also test with a task that has arguments
cat <<EOF >subdir/mise.toml
[tasks.deploy]
run = 'echo "Deploying {{arg(name="env")}}"'
description = 'Deploy to environment'
EOF

assert_contains "mise run --cd subdir deploy --help 2>&1 || true" "Usage:"
assert_contains "mise run --cd subdir deploy --help 2>&1 || true" "<env>"
assert_not_contains "mise run --cd subdir deploy --help 2>&1 || true" "Deploying"

# Note: For tasks WITH usage specs (arg() calls), the usage library itself
# intercepts --help even after --, so mise run deploy -- --help also shows help
