package main

import (
	"embed"
	_ "embed"
	"flag"
	"fmt"
	"os"

	"github.com/fatih/color"

	"fes/src/config"
	"fes/src/new"
	"fes/src/server"
)

//go:embed core/*
var core embed.FS

func init() {
	config.Port = flag.Int("p", 3000, "Set the server port for http")
	config.HTTPSPort = flag.Int("ps", 3000, "Set the server port for https")
	config.Color = flag.Bool("no-color", false, "Disable color output")
	config.Core = core
}

func main() {
	flag.Parse()
	if len(os.Args) < 3 {
		fmt.Println("Usage: fes <command> <project_dir>")
		os.Exit(1)
	}

	if *config.Color {
		color.NoColor = true
	}

	cmd := os.Args[1]
	dir := os.Args[2]

	switch cmd {
	case "new":
		if err := new.Project(dir); err != nil {
			panic(err)
		}
	case "run":
		if err := server.Start(dir); err != nil {
			panic(err)
		}
	default:
		fmt.Println("Unknown command:", cmd)
		os.Exit(1)
	}
}
