Skip to content

Commit

Permalink
Merge pull request #59 from kcmvp/plugin-install
Browse files Browse the repository at this point in the history
#56: download plugin on demand
  • Loading branch information
kcmvp authored Jan 15, 2024
2 parents 4945d1e + bc47d15 commit 7ce97dd
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 17 deletions.
1 change: 0 additions & 1 deletion cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func execute(cmd *cobra.Command, arg string) error {
if err := plugin.Execute(); err != nil {
return err
}
reportAction(cmd, arg)
return nil
} else if action, ok := lo.Find(builtinActions, func(action Action) bool {
return action.A == arg
Expand Down
7 changes: 4 additions & 3 deletions cmd/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ func TestActionSuite(t *testing.T) {
func (suite *ActionTestSuite) SetupSuite() {
os.Remove(suite.binary)
}
func (suite *ActionTestSuite) TearDownSuite() {
os.Remove(suite.binary)
}

//func (suite *ActionTestSuite) TearDownSuite() {
// os.Remove(suite.binary)
//}

func (suite *ActionTestSuite) TestBuildClean() {
err := buildAction(nil)
Expand Down
4 changes: 2 additions & 2 deletions cmd/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var builderCmd = &cobra.Command{
}
return cobra.MinimumNArgs(1)(cmd, args)
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return internal.CurProject().Validate()
PersistentPreRun: func(cmd *cobra.Command, args []string) {
internal.CurProject().Validate()
},
RunE: func(cmd *cobra.Command, args []string) error {
for _, arg := range lo.Uniq(args) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (suite *BuilderTestSuit) TearDownTest() {
}

func (suite *BuilderTestSuit) TestPersistentPreRun() {
builderCmd.PersistentPreRunE(nil, nil)
builderCmd.PersistentPreRun(nil, nil)
hooks := lo.MapToSlice(internal.HookScripts(), func(key string, _ string) string {
return key
})
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions internal/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ func (plugin Plugin) install() error {
}

func (plugin Plugin) Execute() error {
if err := plugin.install(); err != nil {
return err
}
exeCmd := exec.Command(plugin.Binary(), strings.Split(plugin.Args, " ")...) //nolint #gosec
return shared.StreamCmdOutput(exeCmd, filepath.Join(CurProject().Target(), fmt.Sprintf("%s.log", plugin.logName())))
}
6 changes: 1 addition & 5 deletions internal/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,8 @@ func (project *Project) isSetup(plugin Plugin) bool {
return project.config().Get(fmt.Sprintf("plugins.%s.url", plugin.name)) != nil
}

func (project *Project) Validate() error {
func (project *Project) Validate() {
project.SetupHooks(false)
lo.ForEach(project.Plugins(), func(plugin Plugin, _ int) {
plugin.install() //nolint
})
return nil
}

func InGit() bool {
Expand Down
5 changes: 0 additions & 5 deletions internal/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ func (suite *ProjectTestSuite) TestIsSetup() {

func (suite *ProjectTestSuite) TestValidate() {
CurProject().Validate()
lo.ForEach(CurProject().Plugins(), func(plugin Plugin, _ int) {
info, err := os.Stat(filepath.Join(suite.goPath, plugin.Binary()))
assert.NoError(suite.T(), err)
assert.True(suite.T(), info.Size() > 0)
})
CurProject().GitHook()
for name, _ := range HookScripts() {
_, err := os.Stat(filepath.Join(CurProject().HookDir(), name))
Expand Down
Empty file removed root.md
Empty file.

0 comments on commit 7ce97dd

Please sign in to comment.