alpha p10

This commit is contained in:
2025-12-07 12:24:47 -05:00
parent 4ff689e299
commit 8dca9ab5da
39 changed files with 124 additions and 309 deletions

54
main.go
View File

@@ -2,7 +2,7 @@ package main
import (
"embed"
_ "embed"
"errors"
"flag"
"fmt"
"os"
@@ -10,6 +10,7 @@ import (
"github.com/fatih/color"
"fes/src/config"
"fes/src/doc"
"fes/src/new"
"fes/src/server"
)
@@ -24,30 +25,63 @@ func init() {
}
func main() {
flag.Parse()
if len(os.Args) < 3 {
fmt.Println("Usage: fes <command> <project_dir>")
os.Exit(1)
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] <command> <project_dir>\n", os.Args[0])
fmt.Println("Commands:")
fmt.Println(" new <project_dir> Create a new project")
fmt.Println(" doc Open documentation")
fmt.Println(" run <project_dir> Start the server")
fmt.Println("Options:")
flag.PrintDefaults()
}
flag.Parse()
if *config.Color {
color.NoColor = true
}
cmd := os.Args[1]
dir := os.Args[2]
args := flag.Args()
if len(args) < 1 {
flag.Usage()
os.Exit(1)
}
cmd := args[0]
var dir string
if cmd == "new" || cmd == "run" {
if len(args) < 2 {
fmt.Fprintf(os.Stderr, "Error: %s requires <project_dir>\n", cmd)
flag.Usage()
os.Exit(1)
}
dir = args[1]
}
switch cmd {
case "new":
if err := new.Project(dir); err != nil {
panic(err)
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
case "doc":
if err := doc.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
case "run":
if err := server.Start(dir); err != nil {
panic(err)
if errors.Is(err, os.ErrNotExist) {
fmt.Fprintf(os.Stderr, "%s does not exist\n", dir)
fmt.Fprintf(os.Stderr, "Try: fes new %s\n", dir)
os.Exit(1)
} else {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
}
default:
fmt.Println("Unknown command:", cmd)
fmt.Fprintf(os.Stderr, "Unknown command: %s\n", cmd)
flag.Usage()
os.Exit(1)
}
}