Create function for asking yes or no questions
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

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