Skip to content

refactor: split monolithic main.go into domain-specific command files#27

Merged
stuffbucket merged 1 commit intomainfrom
refactor/split-main-commands
Feb 11, 2026
Merged

refactor: split monolithic main.go into domain-specific command files#27
stuffbucket merged 1 commit intomainfrom
refactor/split-main-commands

Conversation

@stuffbucket
Copy link
Copy Markdown
Owner

Summary

Split the 2000+ line cmd/coop/main.go into 13 focused files with dependency injection via an App struct.

Changes

File Lines Responsibility
main.go 91 Build vars + command dispatch
app.go 113 App struct, NewApp(), Manager(), validators, initLogging()
cmd_container.go 355 init/create/start/stop/lock/unlock/logs/delete/list/status
cmd_shell.go 99 ssh/shell/exec (incus exec path for bladerunner)
cmd_config.go 124 config/env display
cmd_theme.go 230 interactive theme picker and previews
cmd_snapshot.go 151 snapshot CRUD
cmd_mount.go 272 mount add/remove/list with seatbelt auth
cmd_vm.go 117 VM lifecycle commands
cmd_doctor.go 89 health checks
cmd_image.go 223 image build/list/exists/publish/lineage
cmd_state.go 150 state history/show
cmd_help.go 128 help/version with dashboard

Key design decisions

  • DI via App struct: All command handlers are methods on *App, which holds *config.Config and BuildInfo. No more appConfig global.
  • Lazy Manager(): Sandbox manager is created on first use, not at startup. Commands that don't need it (help, version, config) skip the overhead.
  • Zero behavior changes: Pure structural refactoring. All command logic preserved exactly.
  • Lint clean: Fixed all 23 errcheck issues across bladerunner, doctor, and cmd files.

Verification

  • golangci-lint run: 0 issues
  • go vet ./...: clean
  • go build ./cmd/coop/: OK
  • go test -race ./...: all pass

Extract 2000+ line main.go into 13 focused files with DI via App struct:
- app.go: App struct, NewApp(), Manager(), validators, initLogging()
- cmd_container.go: init/create/start/stop/lock/unlock/logs/delete/list/status
- cmd_shell.go: ssh/shell/exec (incus exec path for bladerunner)
- cmd_config.go: config/env display
- cmd_theme.go: interactive theme picker and previews
- cmd_snapshot.go: snapshot CRUD
- cmd_mount.go: mount add/remove/list with seatbelt auth
- cmd_vm.go: VM lifecycle commands
- cmd_doctor.go: health checks
- cmd_image.go: image build/list/exists/publish/lineage
- cmd_state.go: state history/show
- cmd_help.go: help/version with dashboard
- main.go: thin 91-line dispatch

Eliminates appConfig global; all state flows through App struct.
Fix all errcheck lint issues across bladerunner, doctor, and cmd files.
@stuffbucket stuffbucket merged commit 8215df2 into main Feb 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant