github.com/argoproj/argo-cd/v3@v3.2.1/cmd/argocd/commands/utils/prompt.go (about) 1 package utils 2 3 import ( 4 "github.com/argoproj/argo-cd/v3/util/cli" 5 ) 6 7 type Prompt struct { 8 enabled bool 9 } 10 11 func NewPrompt(promptsEnabled bool) *Prompt { 12 return &Prompt{ 13 enabled: promptsEnabled, 14 } 15 } 16 17 func (p *Prompt) Confirm(message string) bool { 18 if !p.enabled { 19 return true 20 } 21 22 return cli.AskToProceed(message) 23 } 24 25 // ConfirmAll asks the user to confirm an action. If prompts are disabled, it will return true. 26 // support y/n and A, which means all 27 // return if confirm and if all 28 func (p *Prompt) ConfirmAll(message string) (bool, bool) { 29 if !p.enabled { 30 return true, true 31 } 32 33 result := cli.AskToProceedS(message) 34 35 if result == "a" { 36 return true, true 37 } 38 39 if result == "y" { 40 return true, false 41 } 42 43 return false, false 44 } 45 46 func (p *Prompt) ConfirmBaseOnCount(messageForSingle string, messageForArray string, count int) (bool, bool) { 47 if !p.enabled { 48 return true, true 49 } 50 51 if count == 0 { 52 return true, true 53 } 54 55 if count == 1 { 56 return p.Confirm(messageForSingle), false 57 } 58 59 return p.ConfirmAll(messageForArray) 60 }