-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (64 loc) · 2 KB
/
main.go
File metadata and controls
75 lines (64 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"fmt"
"os"
"atlas.facade/internal/model"
"atlas.facade/internal/server"
"atlas.facade/internal/ui"
tea "github.com/charmbracelet/bubbletea"
"github.com/fezcode/go-piml"
)
var Version = "dev"
func main() {
if len(os.Args) > 1 && (os.Args[1] == "-v" || os.Args[1] == "--version") {
fmt.Printf("atlas.facade v%s\n", Version)
return
}
if len(os.Args) > 1 && (os.Args[1] == "-h" || os.Args[1] == "--help" || os.Args[1] == "help") {
fmt.Println("Atlas Facade - Retro-future Pip-Boy style mock API server.")
fmt.Println("\nUsage:")
fmt.Println(" atlas.facade [options]")
fmt.Println("\nOptions:")
fmt.Println(" -port int Port to run the mock server on (default 4000)")
fmt.Println(" -file string PIML file containing route definitions (default \"routes.piml\")")
fmt.Println(" -v, -version Show version information")
fmt.Println(" -h, -help Show this help")
return
}
port := flag.Int("port", 4000, "Port to run the mock server on")
blueprintPath := flag.String("file", "routes.piml", "PIML file containing route definitions")
versionFlag := flag.Bool("version", false, "Show version information")
flag.BoolVar(versionFlag, "v", false, "Show version information")
flag.Parse()
if *versionFlag {
fmt.Printf("atlas.facade v%s\n", Version)
return
}
// 1. Load Blueprint
data, err := os.ReadFile(*blueprintPath)
if err != nil {
fmt.Printf("Error: Blueprint file '%s' not found.\n", *blueprintPath)
os.Exit(1)
}
var blueprint model.Blueprint
if err := piml.Unmarshal(data, &blueprint); err != nil {
fmt.Printf("Error parsing blueprint: %v\n", err)
os.Exit(1)
}
// 2. Init Server
srv := server.NewServer(*port, blueprint.Routes)
// 3. Start Server Goroutine
go func() {
if err := srv.Start(); err != nil {
fmt.Printf("Server Error: %v\n", err)
os.Exit(1)
}
}()
// 4. Start TUI
p := tea.NewProgram(ui.NewModel(srv), tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Printf("TUI Error: %v\n", err)
os.Exit(1)
}
}