package cmd import ( "fmt" "strings" "go.jolheiser.com/gpm/config" "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)", Action: doRemove, } func doRemove(_ *cli.Context) error { cfg, err := config.Load() if err != nil { return err } pkgQuestion := &survey.Input{ Message: "Package name", } var pkgAnswer string if err := survey.AskOne(pkgQuestion, &pkgAnswer); err != nil { return err } for idx, p := range cfg.Packages { if strings.EqualFold(p.Name, pkgAnswer) { confirm := &survey.Confirm{ Message: fmt.Sprintf("Are you sure you want to remove %s (%s) ?", p.Name, p.Import), Default: false, } var answer bool if err := survey.AskOne(confirm, &answer); err != nil { return err } if answer { cfg.Packages = append(cfg.Packages[:idx], cfg.Packages[idx+1:]...) if err := cfg.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 }