diff options
| -rw-r--r-- | flags/flags.go | 1 | ||||
| -rw-r--r-- | menu/confirm.go | 21 |
2 files changed, 20 insertions, 2 deletions
diff --git a/flags/flags.go b/flags/flags.go index 2ce8045..9f62c38 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -9,4 +9,5 @@ var ( All = pflag.BoolP("all", "a", false, "get sources from cache instead of crawling") Dry = pflag.BoolP("dry", "d", false, "print cmdlines instead of running them") Root = pflag.BoolP("root", "r", false, "run targets (including triggers) with sudo") + Yes = pflag.BoolP("yes", "y", false, "auto-confirm y/n confirmations") ) diff --git a/menu/confirm.go b/menu/confirm.go index af6c30d..1c6a535 100644 --- a/menu/confirm.go +++ b/menu/confirm.go @@ -6,6 +6,7 @@ import ( "github.com/charmbracelet/lipgloss" "io" "os" + "pik/flags" "pik/menu/style" "pik/model" "slices" @@ -21,11 +22,21 @@ var confirmations = []rune{ var ( PromptColor = lipgloss.Color("1") PromptStyle = style.New(func() lipgloss.Style { - return lipgloss.NewStyle().Foreground(PromptColor) + st := lipgloss.NewStyle() + if !*flags.Yes { + st.Foreground(PromptColor) + } + return st }) ConfirmStyle = style.New(func() lipgloss.Style { return lipgloss.NewStyle() }) + AnswerStyle = style.New(func() lipgloss.Style { + return lipgloss.NewStyle() + }) + YesStyle = style.New(func() lipgloss.Style { + return lipgloss.NewStyle().Faint(true) + }) ) func Confirm(r io.Reader, source *model.Source, target model.Target, args ...string) bool { @@ -35,7 +46,13 @@ func Confirm(r io.Reader, source *model.Source, target model.Target, args ...str "? ", } banner := BannerStyle.Render(parts...) - fmt.Print(banner) + _, _ = fmt.Fprint(os.Stderr, banner) + + if *flags.Yes { + _, _ = fmt.Fprintln(os.Stderr, AnswerStyle.Render("Y", YesStyle.Render("(--yes)"))) + return true + } + scanner := bufio.NewScanner(r) scanner.Split(bufio.ScanRunes) scanner.Scan() |
