package main

import (
	"fmt"
	"os"

	"github.com/tanagram/cli/commands"
)

func main() {
	// Get subcommand (default to "run" if none provided)
	subcommand := "run"
	if len(os.Args) > 1 {
		subcommand = os.Args[1]
	}

	var err error
	switch subcommand {
	case "run":
		err = commands.Run()
	case "sync":
		err = commands.Sync()
	case "list":
		err = commands.List()
	case "help", "-h", "--help":
		printHelp()
		return
	default:
		fmt.Fprintf(os.Stderr, "Unknown command: %s\n\n", subcommand)
		printHelp()
		os.Exit(1)
	}

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
		os.Exit(1)
	}
}

func printHelp() {
	help := `Tanagram - Policy enforcement for git changes

USAGE:
  tanagram [command]

COMMANDS:
  run      Check git changes against policies (default)
  sync     Manually sync instruction files to cache
  list     Show all cached policies
  help     Show this help message

EXAMPLES:
  tanagram              # Check changes (auto-syncs if files changed)
  tanagram run          # Same as above
  tanagram sync         # Manually sync policies
  tanagram list         # View all cached policies

INSTRUCTION FILES:
  Tanagram looks for instruction files in your git repository:
  - AGENTS.md, POLICIES.md, CLAUDE.md, BUGBOT.md
  - Cursor rules: .cursor/rules/*.mdc

  Policies are cached and automatically resynced when files change.
`
	fmt.Print(help)
}
