Create function for asking yes or no questions
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Elara 2022-11-30 21:58:21 -08:00
parent eaf49a4594
commit 4e71a5c35c
2 changed files with 18 additions and 12 deletions

View File

@ -174,14 +174,11 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
} }
if !archMatches(vars.Architectures) { if !archMatches(vars.Architectures) {
var buildAnyway bool buildAnyway, err := yesNoPrompt("Your system's CPU architecture doesn't match this package. Do you want to build anyway?", true)
survey.AskOne( if err != nil {
&survey.Confirm{ return nil, nil, err
Message: "Your system's CPU architecture doesn't match this package. Do you want to build anyway?", }
Default: true,
},
&buildAnyway,
)
if !buildAnyway { if !buildAnyway {
os.Exit(1) os.Exit(1)
} }
@ -455,10 +452,7 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
} }
if len(buildDeps) > 0 { if len(buildDeps) > 0 {
var removeBuildDeps bool removeBuildDeps, err := yesNoPrompt("Would you like to remove build dependencies?", false)
err = survey.AskOne(&survey.Confirm{
Message: "Would you like to remove build dependencies?",
}, &removeBuildDeps)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

12
cli.go
View File

@ -29,3 +29,15 @@ func pkgPrompt(options []db.Package, verb string) ([]db.Package, error) {
return out, nil return out, nil
} }
func yesNoPrompt(msg string, def bool) (bool, error) {
var answer bool
err := survey.AskOne(
&survey.Confirm{
Message: msg,
Default: def,
},
&answer,
)
return answer, err
}