#!/bin/sh
# minaki -- product front door for Minaki Scan. Bare `minaki` runs a full scan and prints a
# plain-English report (what's wrong, how bad, what to do). Subcommands map to the scanner.
set -eu
SELF_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
SCAN="$SELF_DIR/minaki-scan"; [ -x "$SCAN" ] || SCAN=$(command -v minaki-scan 2>/dev/null) || {
  echo "minaki-scan not found on PATH" >&2; exit 127; }
cmd=${1:-scan}
case "$cmd" in
  scan|"")  if [ $# -gt 0 ]; then shift; fi; exec "$SCAN" "$@" ;;   # dash: a bare `shift` with no args is fatal
  plugins)  shift; exec "$SCAN" --list-plugins "$@" ;;
  privacy)  shift; exec "$SCAN" --privacy "$@" ;;   # what it reads, changes and sends (PRIVACY_DISCLOSURE)
  ask)      shift
            AM="$SELF_DIR/../ask-minaki/ask-minaki"; [ -x "$AM" ] || AM=$(command -v ask-minaki 2>/dev/null) || {
              echo "Ask Minaki is design/prototype only and not installed." >&2; exit 2; }
            exec "$AM" "$@" ;;
  -*)       exec "$SCAN" "$@" ;;          # --advanced / --fix / --json / --root pass straight through
  *)        echo "usage: minaki [scan|plugins|privacy|ask] [options]   (bare 'minaki' runs a scan)"; exit 2 ;;
esac
