This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 574
/
add.go
68 lines (60 loc) · 1.45 KB
/
add.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 (
"context"
"os"
"path"
"strings"
"github.com/gobuffalo/buffalo/genny/add"
"github.com/gobuffalo/buffalo/internal/takeon/github.com/markbates/errx"
"github.com/gobuffalo/buffalo/plugins/plugdeps"
"github.com/gobuffalo/genny/v2"
"github.com/gobuffalo/meta"
"github.com/spf13/cobra"
)
var addOptions = struct {
dryRun bool
buildTags []string
}{}
var addCmd = &cobra.Command{
Use: "add",
Short: "adds plugins to config/buffalo-plugins.toml",
RunE: func(cmd *cobra.Command, args []string) error {
run := genny.WetRunner(context.Background())
if addOptions.dryRun {
run = genny.DryRunner(context.Background())
}
app := meta.New(".")
plugs, err := plugdeps.List(app)
if err != nil && (errx.Unwrap(err) != plugdeps.ErrMissingConfig) {
return err
}
tags := app.BuildTags("", addOptions.buildTags...)
for _, a := range args {
a = strings.TrimSpace(a)
bin := path.Base(a)
plug := plugdeps.Plugin{
Binary: bin,
GoGet: a,
Tags: tags,
}
if _, err := os.Stat(a); err == nil {
plug.Local = a
plug.GoGet = ""
}
plugs.Add(plug)
}
g, err := add.New(&add.Options{
App: app,
Plugins: plugs.List(),
})
if err != nil {
return err
}
run.With(g)
return run.Run()
},
}
func init() {
addCmd.Flags().BoolVarP(&addOptions.dryRun, "dry-run", "d", false, "dry run")
addCmd.Flags().StringSliceVarP(&addOptions.buildTags, "tags", "t", []string{}, "build tags")
}