This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
/
remove.go
68 lines (59 loc) · 1.46 KB
/
remove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package plugins
import (
"bytes"
"context"
"fmt"
"path"
"strings"
"github.com/gobuffalo/bufcli/plugins/plugdeps"
"github.com/gobuffalo/genny"
"github.com/gobuffalo/meta"
"github.com/markbates/errx"
"github.com/spf13/cobra"
)
var removeOptions = struct {
dryRun bool
vendor bool
}{}
var removeCmd = &cobra.Command{
Use: "remove",
Short: "removes plugin from config/buffalo-plugins.toml",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return fmt.Errorf("you must specify at least one package")
}
run := genny.WetRunner(context.Background())
if removeOptions.dryRun {
run = genny.DryRunner(context.Background())
}
app := meta.New(".")
plugs, err := plugdeps.List(app)
if err != nil && (errx.Unwrap(err) != plugdeps.ErrMissingConfig) {
return err
}
for _, a := range args {
a = strings.TrimSpace(a)
bin := path.Base(a)
plugs.Remove(plugdeps.Plugin{
Binary: bin,
GoGet: a,
})
}
run.WithRun(func(r *genny.Runner) error {
p := plugdeps.ConfigPath(app)
bb := &bytes.Buffer{}
if err := plugs.Encode(bb); err != nil {
return err
}
return r.File(genny.NewFile(p, bb))
})
if err != nil {
return err
}
return run.Run()
},
}
func init() {
removeCmd.Flags().BoolVarP(&removeOptions.dryRun, "dry-run", "d", false, "dry run")
removeCmd.Flags().BoolVar(&removeOptions.vendor, "vendor", false, "will install plugin binaries into ./plugins [WINDOWS not currently supported]")
}