Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #84 from gochigo/hotfix-plugin-management
Browse files Browse the repository at this point in the history
fixed plugin management related bugs
  • Loading branch information
paganotoni authored Dec 16, 2021
2 parents 17b1c36 + 2efa83e commit 08e8efd
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 53 deletions.
15 changes: 8 additions & 7 deletions internal/cmd/fix/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"errors"
"fmt"
"os"
"path"
"strings"

"github.com/gobuffalo/cli/internal/genny/plugins/install"

Expand All @@ -17,6 +15,8 @@ import (
"github.com/gobuffalo/meta"
)

var current_pop = "github.com/gobuffalo/buffalo-pop/v3"

//Plugins fixes the plugin configuration of the project by
//manipulating the plugins .toml file.
type Plugins struct{}
Expand All @@ -35,6 +35,10 @@ func (pf Plugins) Reinstall(r *Runner) error {
return err
}

// TODO: generalize with meta/v2
if r.App.WithPop {
plugs.Add(plugdeps.NewPlugin(current_pop))
}
run := genny.WetRunner(context.Background())
gg, err := install.New(&install.Options{
App: r.App,
Expand All @@ -61,14 +65,11 @@ func (pf Plugins) RemoveOld(r *Runner) error {
return err
}

a := strings.TrimSpace("github.com/gobuffalo/buffalo-pop")
bin := path.Base(a)
plugs.Remove(plugdeps.Plugin{
Binary: bin,
GoGet: a,
Binary: "buffalo-pop",
})

fmt.Println("~~~ Removing github.com/gobuffalo/buffalo-pop plugin ~~~")
fmt.Println("~~~ Removing previous version of buffalo-pop plugin ~~~")

run.WithRun(cmdPlugins.NewEncodePluginsRunner(app, plugs))

Expand Down
16 changes: 1 addition & 15 deletions internal/cmd/plugins/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package plugins
import (
"context"
"errors"
"os"
"path"
"strings"

"github.com/gobuffalo/cli/internal/genny/add"
"github.com/gobuffalo/cli/internal/plugins/plugdeps"
Expand Down Expand Up @@ -36,18 +33,7 @@ var addCmd = &cobra.Command{

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)
plugs.Add(plugdeps.NewPlugin(a, tags))
}
g, err := add.New(&add.Options{
App: app,
Expand Down
1 change: 0 additions & 1 deletion internal/cmd/plugins/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ func init() {
cacheCmd.AddCommand(cache.CleanCmd)
cacheCmd.AddCommand(cache.ListCmd)
cacheCmd.AddCommand(cache.BuildCmd)
PluginsCmd.AddCommand(cacheCmd)
}
15 changes: 1 addition & 14 deletions internal/cmd/plugins/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"context"
"errors"
"io"
"os"
"path"
"strings"

"github.com/gobuffalo/cli/internal/genny/plugins/install"
"github.com/gobuffalo/cli/internal/plugins/plugdeps"
Expand Down Expand Up @@ -48,17 +45,7 @@ var installCmd = &cobra.Command{
}

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)
plugs.Add(plugdeps.NewPlugin(a))
}
gg, err := install.New(&install.Options{
App: app,
Expand Down
9 changes: 3 additions & 6 deletions internal/cmd/plugins/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"path"
"strings"

"github.com/gobuffalo/cli/internal/plugins/plugdeps"
Expand All @@ -23,7 +22,7 @@ var removeCmd = &cobra.Command{
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")
return fmt.Errorf("you must specify at least one plugin")
}
run := genny.WetRunner(context.Background())
if removeOptions.dryRun {
Expand All @@ -36,12 +35,10 @@ var removeCmd = &cobra.Command{
return err
}

for _, a := range args {
a = strings.TrimSpace(a)
bin := path.Base(a)
for _, bin := range args {
bin = strings.TrimSpace(bin)
plugs.Remove(plugdeps.Plugin{
Binary: bin,
GoGet: a,
})
}

Expand Down
3 changes: 0 additions & 3 deletions internal/plugins/plugdeps/plugdeps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ var ErrMissingConfig = fmt.Errorf("could not find a buffalo-plugins config file
// Use plugdeps#On(app) to test if plugdeps are being used.
func List(app meta.App) (*Plugins, error) {
plugs := New()
if app.WithPop {
plugs.Add(pop)
}

lp, err := listLocal(app)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/plugins/plugdeps/plugdeps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"github.com/stretchr/testify/require"
)

var pop = Plugin{
Binary: "buffalo-pop",
GoGet: "github.com/gobuffalo/buffalo-pop/v3@latest",
}

var heroku = Plugin{
Binary: "buffalo-heroku",
GoGet: "github.com/gobuffalo/buffalo-heroku@latest",
Expand Down
31 changes: 30 additions & 1 deletion internal/plugins/plugdeps/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ package plugdeps

import (
"encoding/json"
"os"
"regexp"
"strings"

"github.com/gobuffalo/meta"
)

// bin, module version, and tag
var re = regexp.MustCompile(`.*(buffalo-[^/]+)/?(v[0-9]+)?@?(.*)?`)

// Plugin represents a Go plugin for Buffalo applications
type Plugin struct {
Binary string `toml:"binary" json:"binary"`
Expand All @@ -22,5 +28,28 @@ func (p Plugin) String() string {
}

func (p Plugin) key() string {
return p.Binary + p.GoGet + p.Local
// p.Binary should be uniq and it can be used as the key
return p.Binary
}

func NewPlugin(mod string, tags ...meta.BuildTags) Plugin {
mod = strings.TrimSpace(mod)
match := re.FindStringSubmatch(mod)
bin := match[1]
tag := match[3]
plug := Plugin{
Binary: bin,
GoGet: mod,
}
if len(tags) > 0 {
plug.Tags = tags[0]
}
if _, err := os.Stat(mod); err == nil {
plug.Local = mod
plug.GoGet = ""
}
if plug.GoGet != "" && tag == "" {
plug.GoGet = mod + "@latest"
}
return plug
}
6 changes: 0 additions & 6 deletions internal/plugins/plugdeps/pop.go

This file was deleted.

0 comments on commit 08e8efd

Please sign in to comment.