Skip to content

Commit 3252605

Browse files
committed
Add --yes flag to remove prompt for user selection
and to use the previous selection upon exection.
1 parent b49514d commit 3252605

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

main.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ package main
22

33
import (
44
"bytes"
5+
"flag"
56
"fmt"
67
"macup/macup"
78
"os"
89
)
910

1011
// Entry point of the update script
1112
func main() {
13+
// Define and parse the --yes flag
14+
yes := flag.Bool("yes", false, "Use previous selections without prompting")
15+
flag.Parse()
16+
1217
// Check for internet connectivity before proceeding
1318
if !macup.CheckInternet() {
1419
os.Exit(1)
@@ -22,17 +27,26 @@ func main() {
2227
}
2328

2429
// Prompt the user to select updates
25-
selectedUpdates, err := macup.SelectUpdates(config)
26-
if err != nil {
27-
fmt.Fprintf(os.Stderr, "Error selecting updates: %v\n", err)
28-
os.Exit(1)
29-
}
30+
var selectedUpdates []string
31+
if *yes && len(config.SelectedUpdates) > 0 {
32+
selectedUpdates = config.SelectedUpdates
33+
} else {
34+
if *yes {
35+
println("No previous updates selected. Prompting for selection.")
36+
}
37+
var err error
38+
selectedUpdates, err = macup.SelectUpdates(config)
39+
if err != nil {
40+
fmt.Fprintf(os.Stderr, "Error selecting updates: %v\n", err)
41+
os.Exit(1)
42+
}
3043

31-
// Save the user's selections
32-
config.SelectedUpdates = selectedUpdates
33-
if err := config.SaveConfig(); err != nil {
34-
fmt.Fprintf(os.Stderr, "Error saving config: %v\n", err)
35-
os.Exit(1)
44+
// Save the user's selections
45+
config.SelectedUpdates = selectedUpdates
46+
if err := config.SaveConfig(); err != nil {
47+
fmt.Fprintf(os.Stderr, "Error saving config: %v\n", err)
48+
os.Exit(1)
49+
}
3650
}
3751

3852
// Run the selected updates

0 commit comments

Comments
 (0)