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
/
install.go
85 lines (76 loc) · 2 KB
/
install.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package plugins
import (
"bytes"
"context"
"io"
"os"
"path"
"strings"
"github.com/gobuffalo/buffalo/genny/plugins/install"
"github.com/gobuffalo/buffalo/internal/takeon/github.com/markbates/errx"
"github.com/gobuffalo/buffalo/plugins/plugdeps"
"github.com/gobuffalo/genny/v2"
"github.com/gobuffalo/logger"
"github.com/gobuffalo/meta"
"github.com/spf13/cobra"
)
var installOptions = struct {
dryRun bool
vendor bool
verbose bool
}{}
var installCmd = &cobra.Command{
Use: "install",
Short: "installs plugins listed in config/buffalo-plugins.toml",
RunE: func(cmd *cobra.Command, args []string) error {
run := genny.WetRunner(context.Background())
if installOptions.dryRun {
run = genny.DryRunner(context.Background())
if installOptions.vendor {
run.FileFn = func(f genny.File) (genny.File, error) {
bb := &bytes.Buffer{}
if _, err := io.Copy(bb, f); err != nil {
return f, err
}
return genny.NewFile(f.Name(), bb), nil
}
}
}
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)
plug := plugdeps.Plugin{
Binary: bin,
GoGet: a,
}
if _, err := os.Stat(a); err == nil {
plug.Local = a
plug.GoGet = ""
}
plugs.Add(plug)
}
gg, err := install.New(&install.Options{
App: app,
Plugins: plugs.List(),
Vendor: installOptions.vendor,
})
if err != nil {
return err
}
run.WithGroup(gg)
if installOptions.verbose {
run.Logger = logger.New(logger.DebugLevel)
}
return run.Run()
},
}
func init() {
installCmd.Flags().BoolVarP(&installOptions.dryRun, "dry-run", "d", false, "dry run")
installCmd.Flags().BoolVarP(&installOptions.verbose, "verbose", "v", false, "turn on verbose logging")
installCmd.Flags().BoolVar(&installOptions.vendor, "vendor", false, "will install plugin binaries into ./plugins [WINDOWS not currently supported]")
}