Skip to content

Commit 8fcd6b7

Browse files
committed
refactor: de-AIify codebase — eliminate duplication and mechanical patterns
- Extract system.HomeDir() to eliminate 9 duplicated error messages - Refactor cleaner.Execute() from 3 copy-paste blocks to data-driven loop - Collapse CaptureFormulae/Casks/Taps into captureBrewList() helper - Split cli/snapshot.go long functions into focused helpers - Remove mechanical godoc comments, section dividers, and inline narration - Clean up 15+ files for authenticity and maintainability Zero behavior changes. All tests pass, go vet clean.
1 parent 10d3124 commit 8fcd6b7

17 files changed

Lines changed: 224 additions & 197 deletions

File tree

internal/auth/login.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ func pollOnce(pollURL string) (*cliPollResponse, bool, error) {
179179
return nil, false, nil
180180
}
181181

182-
// openBrowserFunc is the function used to open URLs in the browser.
183-
// It is a variable so tests can replace it with a no-op.
184182
var openBrowserFunc = func(url string) error {
185183
return exec.Command("open", url).Start()
186184
}

internal/brew/brew.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"syscall"
1212
"time"
1313

14+
"github.com/openbootdotdev/openboot/internal/system"
1415
"github.com/openbootdotdev/openboot/internal/ui"
1516
)
1617

@@ -665,9 +666,9 @@ func CheckNetwork() error {
665666

666667
func CheckDiskSpace() (float64, error) {
667668
var stat syscall.Statfs_t
668-
home, err := os.UserHomeDir()
669+
home, err := system.HomeDir()
669670
if err != nil {
670-
return 0, fmt.Errorf("cannot determine home directory: %w", err)
671+
return 0, err
671672
}
672673
if err := syscall.Statfs(home, &stat); err != nil {
673674
return 0, err

internal/cleaner/cleaner.go

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/openbootdotdev/openboot/internal/ui"
1010
)
1111

12-
// CleanResult holds the diff between current system and desired state.
1312
type CleanResult struct {
1413
ExtraFormulae []string
1514
ExtraCasks []string
@@ -35,27 +34,23 @@ func DiffFromLists(formulae, casks, npmPkgs []string) (*CleanResult, error) {
3534
func diff(desiredFormulae, desiredCasks, desiredNpm map[string]bool) (*CleanResult, error) {
3635
result := &CleanResult{}
3736

38-
// Get currently installed brew packages
3937
installedFormulae, installedCasks, err := brew.GetInstalledPackages()
4038
if err != nil {
4139
return nil, fmt.Errorf("failed to get installed brew packages: %w", err)
4240
}
4341

44-
// Find extra formulae
4542
for pkg := range installedFormulae {
4643
if !desiredFormulae[pkg] {
4744
result.ExtraFormulae = append(result.ExtraFormulae, pkg)
4845
}
4946
}
5047

51-
// Find extra casks
5248
for pkg := range installedCasks {
5349
if !desiredCasks[pkg] {
5450
result.ExtraCasks = append(result.ExtraCasks, pkg)
5551
}
5652
}
5753

58-
// Find extra npm packages
5954
if npm.IsAvailable() {
6055
installedNpm, err := npm.GetInstalledPackages()
6156
if err != nil {
@@ -72,34 +67,40 @@ func diff(desiredFormulae, desiredCasks, desiredNpm map[string]bool) (*CleanResu
7267
return result, nil
7368
}
7469

75-
// Execute removes the extra packages identified in a CleanResult.
7670
func Execute(result *CleanResult, dryRun bool) error {
77-
var errs []error
78-
79-
if len(result.ExtraFormulae) > 0 {
80-
fmt.Println()
81-
ui.Header("Removing extra formulae")
82-
fmt.Println()
83-
if err := brew.Uninstall(result.ExtraFormulae, dryRun); err != nil {
84-
errs = append(errs, fmt.Errorf("formulae cleanup: %w", err))
85-
}
71+
type uninstallOp struct {
72+
label string
73+
pkgs []string
74+
uninstall func([]string, bool) error
8675
}
8776

88-
if len(result.ExtraCasks) > 0 {
89-
fmt.Println()
90-
ui.Header("Removing extra casks")
91-
fmt.Println()
92-
if err := brew.UninstallCask(result.ExtraCasks, dryRun); err != nil {
93-
errs = append(errs, fmt.Errorf("cask cleanup: %w", err))
94-
}
77+
ops := []uninstallOp{
78+
{
79+
label: "Removing extra formulae",
80+
pkgs: result.ExtraFormulae,
81+
uninstall: brew.Uninstall,
82+
},
83+
{
84+
label: "Removing extra casks",
85+
pkgs: result.ExtraCasks,
86+
uninstall: brew.UninstallCask,
87+
},
88+
{
89+
label: "Removing extra npm packages",
90+
pkgs: result.ExtraNpm,
91+
uninstall: npm.Uninstall,
92+
},
9593
}
9694

97-
if len(result.ExtraNpm) > 0 {
98-
fmt.Println()
99-
ui.Header("Removing extra npm packages")
100-
fmt.Println()
101-
if err := npm.Uninstall(result.ExtraNpm, dryRun); err != nil {
102-
errs = append(errs, fmt.Errorf("npm cleanup: %w", err))
95+
var errs []error
96+
for _, op := range ops {
97+
if len(op.pkgs) > 0 {
98+
fmt.Println()
99+
ui.Header(op.label)
100+
fmt.Println()
101+
if err := op.uninstall(op.pkgs, dryRun); err != nil {
102+
errs = append(errs, fmt.Errorf("%s: %w", op.label, err))
103+
}
103104
}
104105
}
105106

internal/cli/clean.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ func runClean(cmd *cobra.Command) error {
7474
return nil
7575
}
7676

77-
// Show what would be removed
7877
showCleanPreview(result)
7978

80-
// Confirm unless dry-run
8179
if !dryRun {
8280
proceed, err := ui.Confirm(fmt.Sprintf("Remove %d packages?", result.TotalExtra()), false)
8381
if err != nil {

internal/cli/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ shell configuration, and macOS preferences.`,
4444
}
4545
}
4646

47-
// Read OPENBOOT_PRESET env var (works in both interactive and silent modes)
4847
if preset := os.Getenv("OPENBOOT_PRESET"); preset != "" && cfg.Preset == "" {
4948
cfg.Preset = preset
5049
}

0 commit comments

Comments
 (0)