2022-12-01 05:43:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/AlecAivazis/survey/v2"
|
|
|
|
"go.arsenm.dev/lure/internal/db"
|
|
|
|
)
|
|
|
|
|
2022-12-01 06:15:34 +00:00
|
|
|
// pkgPrompt asks the user to choose between multiple packages.
|
|
|
|
// The user may choose multiple packages.
|
2022-12-01 05:43:52 +00:00
|
|
|
func pkgPrompt(options []db.Package, verb string) ([]db.Package, error) {
|
|
|
|
names := make([]string, len(options))
|
|
|
|
for i, option := range options {
|
|
|
|
names[i] = option.Repository + "/" + option.Name + " " + option.Version
|
|
|
|
}
|
|
|
|
|
|
|
|
prompt := &survey.MultiSelect{
|
|
|
|
Options: names,
|
|
|
|
Message: "Choose which package(s) to " + verb,
|
|
|
|
}
|
|
|
|
|
|
|
|
var choices []int
|
|
|
|
err := survey.AskOne(prompt, &choices)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
out := make([]db.Package, len(choices))
|
|
|
|
for i, choiceIndex := range choices {
|
|
|
|
out[i] = options[choiceIndex]
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
2022-12-01 05:58:21 +00:00
|
|
|
|
2022-12-01 06:15:34 +00:00
|
|
|
// yesNoPrompt asks the user a yes or no question, using def as the default answer
|
2022-12-01 05:58:21 +00:00
|
|
|
func yesNoPrompt(msg string, def bool) (bool, error) {
|
|
|
|
var answer bool
|
|
|
|
err := survey.AskOne(
|
|
|
|
&survey.Confirm{
|
|
|
|
Message: msg,
|
|
|
|
Default: def,
|
|
|
|
},
|
|
|
|
&answer,
|
|
|
|
)
|
|
|
|
return answer, err
|
|
|
|
}
|