#!/usr/bin/env bash

export MISE_EXPERIMENTAL=1

cat <<'EOF' >mise.toml
monorepo_root = true

[monorepo]
config_roots = ["projects/frontend"]

[tasks.default]
run = 'echo "default task ran"'
EOF

mkdir -p projects/frontend
cat <<'EOF' >projects/frontend/mise.toml
[tasks.child]
run = 'echo "child task ran"'
EOF

assert "mise run" "default task ran"

# The default task is selected first, so move down once to select the child task.
if [[ $(uname) == Darwin ]]; then
  output=$(printf '\033[B\r' | script -q /dev/null mise run --all)
else
  output=$(printf '\033[B\r' | script -qec 'mise run --all' /dev/null)
fi
if [[ $output != *"child task ran"* ]]; then
  echo "interactive selector did not run the child task"
  exit 1
fi

assert_fail_contains "mise run --all default" "cannot be used with"
assert_fail_contains "mise run --all --affected" "cannot be used with"
