51 lines
1004 B
Go
51 lines
1004 B
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.jolheiser.com/gpm/cmd/flags"
|
|
"go.jolheiser.com/gpm/database"
|
|
"go.jolheiser.com/gpm/go-gpm"
|
|
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/urfave/cli/v2"
|
|
"go.jolheiser.com/beaver"
|
|
)
|
|
|
|
var Remove = cli.Command{
|
|
Name: "remove",
|
|
Aliases: []string{"rm"},
|
|
Usage: "Remove package(s)",
|
|
Before: localOrToken,
|
|
Action: doRemove,
|
|
}
|
|
|
|
func doRemove(_ *cli.Context) error {
|
|
pkgQuestion := &survey.Input{
|
|
Message: "Package name",
|
|
}
|
|
var pkgAnswer string
|
|
|
|
if err := survey.AskOne(pkgQuestion, &pkgAnswer); err != nil {
|
|
return err
|
|
}
|
|
|
|
if flags.Local {
|
|
db, err := database.Load(flags.Database)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := db.RemovePackage(pkgAnswer); err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
client := gpm.New(flags.Token, gpm.WithServer(flags.Server))
|
|
if err := client.Remove(context.Background(), gpm.Package{Name: pkgAnswer}); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
beaver.Infof("Removed %s", yellow.Format(pkgAnswer))
|
|
return nil
|
|
}
|