2020-10-07 04:11:36 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-02-28 04:20:14 +00:00
|
|
|
"go.jolheiser.com/gpm/go-gpm"
|
2020-10-07 04:11:36 +00:00
|
|
|
|
|
|
|
"github.com/AlecAivazis/survey/v2"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"go.jolheiser.com/beaver"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Search = cli.Command{
|
|
|
|
Name: "search",
|
|
|
|
Aliases: []string{"s"},
|
|
|
|
Usage: "Search packages",
|
2021-02-28 04:20:14 +00:00
|
|
|
Action: doSearch,
|
2020-10-07 04:11:36 +00:00
|
|
|
}
|
|
|
|
|
2021-02-28 04:20:14 +00:00
|
|
|
func doSearch(_ *cli.Context) error {
|
|
|
|
pkgs, err := listPackages()
|
2020-10-07 04:11:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-28 04:20:14 +00:00
|
|
|
pkgSlice := make([]string, len(pkgs))
|
|
|
|
pkgMap := make(map[string]gpm.Package)
|
|
|
|
for idx, pkg := range pkgs {
|
|
|
|
pkgSlice[idx] = pkg.Name
|
|
|
|
pkgMap[pkg.Name] = pkg
|
2020-10-07 04:11:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
q := &survey.MultiSelect{
|
|
|
|
Message: "Select packages",
|
2021-02-28 04:20:14 +00:00
|
|
|
Options: pkgSlice,
|
2020-10-07 04:11:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var a []string
|
|
|
|
if err := survey.AskOne(q, &a); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range a {
|
2021-02-28 04:20:14 +00:00
|
|
|
pkg, ok := pkgMap[name]
|
2020-10-07 04:11:36 +00:00
|
|
|
if !ok {
|
|
|
|
beaver.Errorf("could not find package for `%s`", name)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
beaver.Infof("getting `%s`...", name)
|
|
|
|
if err := goGet(pkg.Import); err != nil {
|
|
|
|
beaver.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|