-
Notifications
You must be signed in to change notification settings - Fork 1
add -yes flag and modify README #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,12 +34,14 @@ func (m *multiFlag) Set(v string) error { *m = append(*m, v); return nil } | |||||||||||||||||||||||||
| var ( | ||||||||||||||||||||||||||
| imageFlag string | ||||||||||||||||||||||||||
| diskFlag string | ||||||||||||||||||||||||||
| yesFlag bool | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| func init() { | ||||||||||||||||||||||||||
| flag.StringVar(&imageFlag, "image", | ||||||||||||||||||||||||||
| "ghcr.io/cozystack/cozystack/talos:v1.10.5", "Talos installer image") | ||||||||||||||||||||||||||
| flag.StringVar(&diskFlag, "disk", "", "target disk (will be wiped)") | ||||||||||||||||||||||||||
| flag.BoolVar(&yesFlag, "yes", false, "automatic yes to prompts") | ||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The help text for the
Suggested change
|
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /* ------------------------------ helpers ----------------------------------- */ | ||||||||||||||||||||||||||
|
|
@@ -96,6 +98,10 @@ func fakeCert() string { | |||||||||||||||||||||||||
| var reader = bufio.NewReader(os.Stdin) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| func ask(msg, def string) string { | ||||||||||||||||||||||||||
| if yesFlag { | ||||||||||||||||||||||||||
| fmt.Printf("%s [%s]: %s\n", msg, def, def) | ||||||||||||||||||||||||||
| return def | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| fmt.Printf("%s [%s]: ", msg, def) | ||||||||||||||||||||||||||
| t, _ := reader.ReadString('\n') | ||||||||||||||||||||||||||
| t = strings.TrimSpace(t) | ||||||||||||||||||||||||||
|
|
@@ -106,6 +112,9 @@ func ask(msg, def string) string { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| func askRequired(msg string) string { | ||||||||||||||||||||||||||
| if yesFlag { | ||||||||||||||||||||||||||
| log.Fatalf("missing required input for: %s (cannot auto-fill)", msg) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| for { | ||||||||||||||||||||||||||
| fmt.Printf("%s: ", msg) | ||||||||||||||||||||||||||
| t, _ := reader.ReadString('\n') | ||||||||||||||||||||||||||
|
|
@@ -117,6 +126,10 @@ func askRequired(msg string) string { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| func askYesNo(msg string, def bool) bool { | ||||||||||||||||||||||||||
| if yesFlag { | ||||||||||||||||||||||||||
| fmt.Printf("%s [%s]: %v\n", msg, map[bool]string{true: "yes", false: "no"}[def], def) | ||||||||||||||||||||||||||
| return def | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+129
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation creates a new map on every function call, which is inefficient. Using an Additionally, printing the string "yes" or "no" instead of the boolean
Suggested change
|
||||||||||||||||||||||||||
| defStr := "yes" | ||||||||||||||||||||||||||
| if !def { | ||||||||||||||||||||||||||
| defStr = "no" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other flags in this table, the type for
-extra-kernel-argshould bestringinstead ofvalue. This makes the documentation clearer for users.