Skip to content

Commit e4370ce

Browse files
committed
refactor: full P5 Config struct split into InstallOptions + InstallState
- config.go: add InstallOptions (read-only inputs), InstallState (mutable runtime), ToInstallOptions(), ToInstallState(), ApplyState() methods - installer.go + all step_*.go: internal functions now take (opts *InstallOptions, st *InstallState) instead of *Config; public Run() and RunFromSnapshot() remain unchanged as the boundary - Tests updated to use opts/st instead of cfg where appropriate InstallOptions and InstallState are now distinct types — the compiler enforces that step functions cannot accidentally read input as state or write state back into user-supplied options.
1 parent 73730df commit e4370ce

File tree

8 files changed

+408
-249
lines changed

8 files changed

+408
-249
lines changed

internal/config/config.go

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ var presetsYAML embed.FS
6363
var screenRecordingYAML embed.FS
6464

6565
// Config holds all configuration for a single openboot run.
66-
//
67-
// TODO(future): split into InstallOptions (input, read-only) and
68-
// InstallState (runtime, mutable) once the call-sites are ready.
66+
// See InstallOptions and InstallState for the split representation used
67+
// internally by the installer package.
6968
type Config struct {
7069
// --- Input (set by flags/env before run) ---
7170

@@ -96,6 +95,84 @@ type Config struct {
9695
SnapshotDotfiles string // from snapshot capture
9796
}
9897

98+
// InstallOptions holds user-supplied inputs set from CLI flags and environment
99+
// variables. All fields are read-only after Run() is called.
100+
type InstallOptions struct {
101+
Version string
102+
Preset string
103+
User string
104+
DryRun bool
105+
Silent bool
106+
PackagesOnly bool
107+
Update bool
108+
Shell string
109+
Macos string
110+
Dotfiles string
111+
GitName string
112+
GitEmail string
113+
PostInstall string
114+
AllowPostInstall bool
115+
DotfilesURL string
116+
}
117+
118+
// InstallState holds runtime values populated during installation.
119+
// Fields are written by installer steps and read by subsequent steps.
120+
type InstallState struct {
121+
SelectedPkgs map[string]bool
122+
OnlinePkgs []Package
123+
SnapshotTaps []string
124+
RemoteConfig *RemoteConfig
125+
SnapshotGit *SnapshotGitConfig
126+
SnapshotMacOS []RemoteMacOSPref
127+
SnapshotDotfiles string
128+
}
129+
130+
// ToInstallOptions extracts the read-only input fields from Config.
131+
func (c *Config) ToInstallOptions() *InstallOptions {
132+
return &InstallOptions{
133+
Version: c.Version,
134+
Preset: c.Preset,
135+
User: c.User,
136+
DryRun: c.DryRun,
137+
Silent: c.Silent,
138+
PackagesOnly: c.PackagesOnly,
139+
Update: c.Update,
140+
Shell: c.Shell,
141+
Macos: c.Macos,
142+
Dotfiles: c.Dotfiles,
143+
GitName: c.GitName,
144+
GitEmail: c.GitEmail,
145+
PostInstall: c.PostInstall,
146+
AllowPostInstall: c.AllowPostInstall,
147+
DotfilesURL: c.DotfilesURL,
148+
}
149+
}
150+
151+
// ToInstallState extracts the mutable runtime fields from Config.
152+
func (c *Config) ToInstallState() *InstallState {
153+
return &InstallState{
154+
SelectedPkgs: c.SelectedPkgs,
155+
OnlinePkgs: c.OnlinePkgs,
156+
SnapshotTaps: c.SnapshotTaps,
157+
RemoteConfig: c.RemoteConfig,
158+
SnapshotGit: c.SnapshotGit,
159+
SnapshotMacOS: c.SnapshotMacOS,
160+
SnapshotDotfiles: c.SnapshotDotfiles,
161+
}
162+
}
163+
164+
// ApplyState writes runtime state back into the Config (for callers that still
165+
// use *Config as the shared context, e.g. CLI sync/diff commands).
166+
func (c *Config) ApplyState(s *InstallState) {
167+
c.SelectedPkgs = s.SelectedPkgs
168+
c.OnlinePkgs = s.OnlinePkgs
169+
c.SnapshotTaps = s.SnapshotTaps
170+
c.RemoteConfig = s.RemoteConfig
171+
c.SnapshotGit = s.SnapshotGit
172+
c.SnapshotMacOS = s.SnapshotMacOS
173+
c.SnapshotDotfiles = s.SnapshotDotfiles
174+
}
175+
99176
type SnapshotGitConfig struct {
100177
UserName string
101178
UserEmail string

0 commit comments

Comments
 (0)