57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/urfave/cli/v2"
|
|
"go.jolheiser.com/beaver"
|
|
"go.jolheiser.com/vanity/modules/config"
|
|
"strings"
|
|
)
|
|
|
|
var Remove = cli.Command{
|
|
Name: "remove",
|
|
Aliases: []string{"rm"},
|
|
Usage: "Remove a package",
|
|
Action: doRemove,
|
|
}
|
|
|
|
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{
|
|
Message: fmt.Sprintf("Are you sure you want to remove %s (%s) ?", p.Name, p.Repo),
|
|
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 vanity.", p.Name)
|
|
break
|
|
}
|
|
|
|
beaver.Infof("Did not remove `%s` from vanity.", p.Name)
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|