feat(cli): add archup-installer command entry point with version and cleanup flags
- commit
- c03e113de825040fe12e7dac025075dd746a8bad
- author
- bnema · · 2025-10-26 09:42 UTC
- parent
- 1e96984
- signature
- unsigned
1 file · +81 -0
A cmd/archup-installer/main.go +81 -0
| @@ -0,0 +1,81 @@ | |||
| 1 | + | package main | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "flag" | |
| 5 | + | "fmt" | |
| 6 | + | "os" | |
| 7 | + | ||
| 8 | + | tea "github.com/charmbracelet/bubbletea" | |
| 9 | + | "github.com/bnema/archup/internal/cleanup" | |
| 10 | + | "github.com/bnema/archup/internal/config" | |
| 11 | + | "github.com/bnema/archup/internal/logger" | |
| 12 | + | "github.com/bnema/archup/internal/phases" | |
| 13 | + | "github.com/bnema/archup/internal/ui" | |
| 14 | + | ) | |
| 15 | + | ||
| 16 | + | // version is set via ldflags at build time | |
| 17 | + | // Example: go build -ldflags "-X main.version=v0.3.0" | |
| 18 | + | var version = "dev" | |
| 19 | + | ||
| 20 | + | func main() { | |
| 21 | + | // Parse command-line flags | |
| 22 | + | var ( | |
| 23 | + | showVersion = flag.Bool("version", false, "Show version and exit") | |
| 24 | + | doCleanup = flag.Bool("cleanup", false, "Clean up installation artifacts and exit") | |
| 25 | + | dryRun = flag.Bool("dry-run", false, "Show TUI but don't execute commands") | |
| 26 | + | ) | |
| 27 | + | flag.Parse() | |
| 28 | + | ||
| 29 | + | // Handle --version flag | |
| 30 | + | if *showVersion { | |
| 31 | + | fmt.Printf("archup-installer %s\n", version) | |
| 32 | + | os.Exit(0) | |
| 33 | + | } | |
| 34 | + | ||
| 35 | + | // Create logger with dry-run mode | |
| 36 | + | log, err := logger.New(config.DefaultLogPath, *dryRun) | |
| 37 | + | if err != nil { | |
| 38 | + | fmt.Fprintf(os.Stderr, "Failed to create logger: %v\n", err) | |
| 39 | + | os.Exit(1) | |
| 40 | + | } | |
| 41 | + | ||
| 42 | + | // Handle --cleanup flag | |
| 43 | + | if *doCleanup { | |
| 44 | + | if err := cleanup.Run(log); err != nil { | |
| 45 | + | fmt.Fprintf(os.Stderr, "Cleanup failed: %v\n", err) | |
| 46 | + | os.Exit(1) | |
| 47 | + | } | |
| 48 | + | os.Exit(0) | |
| 49 | + | } | |
| 50 | + | ||
| 51 | + | // Log dry-run mode if enabled | |
| 52 | + | if *dryRun { | |
| 53 | + | log.Info("Running in DRY-RUN mode - commands will be logged but not executed") | |
| 54 | + | } | |
| 55 | + | ||
| 56 | + | // Load or create config | |
| 57 | + | cfg := config.NewConfig() | |
| 58 | + | ||
| 59 | + | // Initialize orchestrator | |
| 60 | + | orchestrator := phases.NewOrchestrator(cfg, config.DefaultLogPath) | |
| 61 | + | ||
| 62 | + | // Register all phases with logger | |
| 63 | + | orchestrator.RegisterPhase(phases.NewBootstrapPhase(cfg, log)) | |
| 64 | + | orchestrator.RegisterPhase(phases.NewPreflightPhase(cfg, log)) | |
| 65 | + | orchestrator.RegisterPhase(phases.NewPartitioningPhase(cfg, log)) | |
| 66 | + | orchestrator.RegisterPhase(phases.NewBaseInstallPhase(cfg, log)) | |
| 67 | + | orchestrator.RegisterPhase(phases.NewConfigPhase(cfg, log)) | |
| 68 | + | orchestrator.RegisterPhase(phases.NewBootPhase(cfg, log)) | |
| 69 | + | orchestrator.RegisterPhase(phases.NewReposPhase(cfg, log)) | |
| 70 | + | orchestrator.RegisterPhase(phases.NewPostInstallPhase(cfg, log)) | |
| 71 | + | ||
| 72 | + | // Create UI model | |
| 73 | + | model := ui.NewModel(orchestrator, cfg, version) | |
| 74 | + | ||
| 75 | + | // Run Bubbletea app | |
| 76 | + | p := tea.NewProgram(model, tea.WithAltScreen()) | |
| 77 | + | if _, err := p.Run(); err != nil { | |
| 78 | + | fmt.Printf("Error running installer: %v\n", err) | |
| 79 | + | os.Exit(1) | |
| 80 | + | } | |
| 81 | + | } | |
| @@ -0,0 +1,81 @@ | |||||
| 1 | + | package main | |||
| 2 | + | ||||
| 3 | + | import ( | |||
| 4 | + | "flag" | |||
| 5 | + | "fmt" | |||
| 6 | + | "os" | |||
| 7 | + | ||||
| 8 | + | tea "github.com/charmbracelet/bubbletea" | |||
| 9 | + | "github.com/bnema/archup/internal/cleanup" | |||
| 10 | + | "github.com/bnema/archup/internal/config" | |||
| 11 | + | "github.com/bnema/archup/internal/logger" | |||
| 12 | + | "github.com/bnema/archup/internal/phases" | |||
| 13 | + | "github.com/bnema/archup/internal/ui" | |||
| 14 | + | ) | |||
| 15 | + | ||||
| 16 | + | // version is set via ldflags at build time | |||
| 17 | + | // Example: go build -ldflags "-X main.version=v0.3.0" | |||
| 18 | + | var version = "dev" | |||
| 19 | + | ||||
| 20 | + | func main() { | |||
| 21 | + | // Parse command-line flags | |||
| 22 | + | var ( | |||
| 23 | + | showVersion = flag.Bool("version", false, "Show version and exit") | |||
| 24 | + | doCleanup = flag.Bool("cleanup", false, "Clean up installation artifacts and exit") | |||
| 25 | + | dryRun = flag.Bool("dry-run", false, "Show TUI but don't execute commands") | |||
| 26 | + | ) | |||
| 27 | + | flag.Parse() | |||
| 28 | + | ||||
| 29 | + | // Handle --version flag | |||
| 30 | + | if *showVersion { | |||
| 31 | + | fmt.Printf("archup-installer %s\n", version) | |||
| 32 | + | os.Exit(0) | |||
| 33 | + | } | |||
| 34 | + | ||||
| 35 | + | // Create logger with dry-run mode | |||
| 36 | + | log, err := logger.New(config.DefaultLogPath, *dryRun) | |||
| 37 | + | if err != nil { | |||
| 38 | + | fmt.Fprintf(os.Stderr, "Failed to create logger: %v\n", err) | |||
| 39 | + | os.Exit(1) | |||
| 40 | + | } | |||
| 41 | + | ||||
| 42 | + | // Handle --cleanup flag | |||
| 43 | + | if *doCleanup { | |||
| 44 | + | if err := cleanup.Run(log); err != nil { | |||
| 45 | + | fmt.Fprintf(os.Stderr, "Cleanup failed: %v\n", err) | |||
| 46 | + | os.Exit(1) | |||
| 47 | + | } | |||
| 48 | + | os.Exit(0) | |||
| 49 | + | } | |||
| 50 | + | ||||
| 51 | + | // Log dry-run mode if enabled | |||
| 52 | + | if *dryRun { | |||
| 53 | + | log.Info("Running in DRY-RUN mode - commands will be logged but not executed") | |||
| 54 | + | } | |||
| 55 | + | ||||
| 56 | + | // Load or create config | |||
| 57 | + | cfg := config.NewConfig() | |||
| 58 | + | ||||
| 59 | + | // Initialize orchestrator | |||
| 60 | + | orchestrator := phases.NewOrchestrator(cfg, config.DefaultLogPath) | |||
| 61 | + | ||||
| 62 | + | // Register all phases with logger | |||
| 63 | + | orchestrator.RegisterPhase(phases.NewBootstrapPhase(cfg, log)) | |||
| 64 | + | orchestrator.RegisterPhase(phases.NewPreflightPhase(cfg, log)) | |||
| 65 | + | orchestrator.RegisterPhase(phases.NewPartitioningPhase(cfg, log)) | |||
| 66 | + | orchestrator.RegisterPhase(phases.NewBaseInstallPhase(cfg, log)) | |||
| 67 | + | orchestrator.RegisterPhase(phases.NewConfigPhase(cfg, log)) | |||
| 68 | + | orchestrator.RegisterPhase(phases.NewBootPhase(cfg, log)) | |||
| 69 | + | orchestrator.RegisterPhase(phases.NewReposPhase(cfg, log)) | |||
| 70 | + | orchestrator.RegisterPhase(phases.NewPostInstallPhase(cfg, log)) | |||
| 71 | + | ||||
| 72 | + | // Create UI model | |||
| 73 | + | model := ui.NewModel(orchestrator, cfg, version) | |||
| 74 | + | ||||
| 75 | + | // Run Bubbletea app | |||
| 76 | + | p := tea.NewProgram(model, tea.WithAltScreen()) | |||
| 77 | + | if _, err := p.Run(); err != nil { | |||
| 78 | + | fmt.Printf("Error running installer: %v\n", err) | |||
| 79 | + | os.Exit(1) | |||
| 80 | + | } | |||
| 81 | + | } | |||