2020-02-19 05:18:36 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-02-19 05:39:54 +00:00
|
|
|
"gitea.com/gpm/gpm/modules/config"
|
2020-02-19 05:18:36 +00:00
|
|
|
"gitea.com/jolheiser/beaver"
|
|
|
|
"github.com/AlecAivazis/survey/v2"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Remove = cli.Command{
|
2020-02-19 16:48:55 +00:00
|
|
|
Name: "remove",
|
|
|
|
Aliases: []string{"rm"},
|
|
|
|
Usage: "Remove a package",
|
|
|
|
Action: doRemove,
|
2020-02-19 05:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func doRemove(ctx *cli.Context) error {
|
|
|
|
pkgQuestion := &survey.Input{
|
|
|
|
Message: "Package name",
|
|
|
|
}
|
|
|
|
var pkgAnswer string
|
|
|
|
|
|
|
|
if err := survey.AskOne(pkgQuestion, &pkgAnswer); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for idx, p := range config.Packages {
|
|
|
|
if strings.EqualFold(p.Name, pkgAnswer) {
|
|
|
|
confirm := &survey.Confirm{
|
2020-02-19 05:39:54 +00:00
|
|
|
Message: fmt.Sprintf("Are you sure you want to remove %s (%s) ?", p.Name, p.Import),
|
2020-02-19 05:18:36 +00:00
|
|
|
Default: false,
|
|
|
|
}
|
|
|
|
var answer bool
|
|
|
|
|
|
|
|
if err := survey.AskOne(confirm, &answer); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if answer {
|
|
|
|
config.Packages = append(config.Packages[:idx], config.Packages[idx+1:]...)
|
|
|
|
if err := config.Save(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
beaver.Infof("Removed `%s` from local gpm.", p.Name)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
beaver.Infof("Did not remove `%s` from local gpm.", p.Name)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|