2020-02-19 05:18:36 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-02-28 04:20:14 +00:00
|
|
|
"context"
|
2020-02-19 05:18:36 +00:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2020-10-07 04:11:36 +00:00
|
|
|
|
2021-02-28 04:20:14 +00:00
|
|
|
"go.jolheiser.com/gpm/cmd/flags"
|
|
|
|
"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"
|
2020-02-19 05:18:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var Get = cli.Command{
|
2021-02-28 04:20:14 +00:00
|
|
|
Name: "get",
|
|
|
|
Usage: "Get package(s)",
|
2020-02-19 05:18:36 +00:00
|
|
|
Action: doGet,
|
|
|
|
}
|
|
|
|
|
|
|
|
func doGet(ctx *cli.Context) error {
|
|
|
|
pkgs := ctx.Args().Slice()
|
|
|
|
if len(pkgs) == 0 {
|
|
|
|
pkgsQuestion := &survey.Multiline{
|
|
|
|
Message: "Enter packages to get, one for each line",
|
|
|
|
}
|
|
|
|
var pkgsAnswer string
|
|
|
|
|
|
|
|
if err := survey.AskOne(pkgsQuestion, &pkgsAnswer); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgs = strings.Split(pkgsAnswer, "\n")
|
|
|
|
}
|
|
|
|
|
2021-02-28 04:20:14 +00:00
|
|
|
client := gpm.New(flags.Token, gpm.WithServer(flags.Server))
|
|
|
|
for _, p := range pkgs {
|
|
|
|
pkg, err := client.Get(context.Background(), p)
|
|
|
|
if err != nil {
|
|
|
|
beaver.Error(err)
|
2020-02-19 17:29:42 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-02-19 05:39:54 +00:00
|
|
|
beaver.Infof("getting `%s`...", pkg)
|
2021-02-28 04:20:14 +00:00
|
|
|
if err := goGet(pkg.Import); err != nil {
|
2020-02-19 05:18:36 +00:00
|
|
|
beaver.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func goGet(url string) error {
|
|
|
|
cmd := exec.Command("go", "get", url)
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
return cmd.Run()
|
|
|
|
}
|