Revert remove command, too easy to remove all packages

Signed-off-by: jolheiser <john.olheiser@gmail.com>
pull/7/head
jolheiser 2021-02-27 22:45:39 -06:00
parent cb0dd34973
commit 2220ab17eb
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
3 changed files with 25 additions and 26 deletions

View File

@ -3,11 +3,11 @@ package cmd
import ( import (
"context" "context"
"errors" "errors"
"go.jolheiser.com/gpm/database"
"os" "os"
"path/filepath" "path/filepath"
"go.jolheiser.com/gpm/cmd/flags" "go.jolheiser.com/gpm/cmd/flags"
"go.jolheiser.com/gpm/database"
"go.jolheiser.com/gpm/go-gpm" "go.jolheiser.com/gpm/go-gpm"
"go.jolheiser.com/gpm/router" "go.jolheiser.com/gpm/router"

View File

@ -2,7 +2,6 @@ package cmd
import ( import (
"context" "context"
"go.jolheiser.com/beaver"
"go.jolheiser.com/gpm/cmd/flags" "go.jolheiser.com/gpm/cmd/flags"
"go.jolheiser.com/gpm/database" "go.jolheiser.com/gpm/database"
@ -10,6 +9,7 @@ import (
"github.com/AlecAivazis/survey/v2" "github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.jolheiser.com/beaver"
) )
var Remove = cli.Command{ var Remove = cli.Command{
@ -33,38 +33,36 @@ func doRemove(_ *cli.Context) error {
pkgMap[pkg.Name] = pkg pkgMap[pkg.Name] = pkg
} }
pkgQuestion := &survey.MultiSelect{ pkgQuestion := &survey.Select{
Message: "Select package to remove", Message: "Select package to remove",
Options: pkgSlice, Options: pkgSlice,
} }
var pkgNames []string var pkgName string
if err := survey.AskOne(pkgQuestion, &pkgNames); err != nil { if err := survey.AskOne(pkgQuestion, &pkgName); err != nil {
return err return err
} }
for _, pkgName := range pkgNames { pkg := gpm.Package{
pkg := gpm.Package{ Name: pkgName,
Name: pkgName, Import: pkgMap[pkgName].Import,
Import: pkgMap[pkgName].Import,
}
if flags.Local {
db, err := database.Load(flags.Database)
if err != nil {
return err
}
if err := db.RemovePackage(pkg.Name); err != nil {
return err
}
} else {
client := gpm.New(flags.Token, gpm.WithServer(flags.Server))
if err := client.Remove(context.Background(), pkg); err != nil {
return err
}
}
beaver.Infof("Removed %s", yellow.Format(pkgName))
} }
if flags.Local {
db, err := database.Load(flags.Database)
if err != nil {
return err
}
if err := db.RemovePackage(pkg.Name); err != nil {
return err
}
} else {
client := gpm.New(flags.Token, gpm.WithServer(flags.Server))
if err := client.Remove(context.Background(), pkg); err != nil {
return err
}
}
beaver.Infof("Removed %s", yellow.Format(pkgName))
return nil return nil
} }

View File

@ -2,6 +2,7 @@ package cmd
import ( import (
"context" "context"
"go.jolheiser.com/gpm/cmd/flags" "go.jolheiser.com/gpm/cmd/flags"
"go.jolheiser.com/gpm/database" "go.jolheiser.com/gpm/database"
"go.jolheiser.com/gpm/go-gpm" "go.jolheiser.com/gpm/go-gpm"