Move pkgPrompt() to cli.go
This commit is contained in:
parent
6aee3fb310
commit
4e37fbd35b
31
cli.go
Normal file
31
cli.go
Normal 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
25
repo.go
@ -113,28 +113,3 @@ func refreshCmd(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user