Move pkgPrompt() to cli.go

This commit is contained in:
Elara 2022-11-30 21:43:52 -08:00
parent 6aee3fb310
commit 4e37fbd35b
2 changed files with 31 additions and 25 deletions

31
cli.go Normal file
View File

@ -0,0 +1,31 @@
package main
import (
"github.com/AlecAivazis/survey/v2"
"go.arsenm.dev/lure/internal/db"
)
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
}

25
repo.go
View File

@ -113,28 +113,3 @@ func refreshCmd(c *cli.Context) error {
}
return nil
}
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
}