-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from kcmvp/version
add gob setup version
- Loading branch information
Showing
8 changed files
with
127 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,14 +31,14 @@ these tools and frameworks exist independently to solve specific problems. | |
Whenever a new Golang project is started, it requires a series of initialization; | ||
What’s worse is that whenever your switch the development environment, same process have to be repeated! | ||
This project is built to solve this problem by providing a method similar to [Maven](https://maven.apache.org/) | ||
or [Gradle](https://gradle.com/) in the **Java** ecosystem. Please refer [Document](#commands) for details | ||
or [Gradle](https://gradle.com/) in the **Java** ecosystem. Please refer [documents](#commands) for details | ||
|
||
<span id="nav-3"></span> | ||
|
||
## Features | ||
|
||
1. **Everything is a plugin, simple yet powerful !** | ||
2. Build a tool chain and workflow without a line. | ||
2. Define a tool chain and workflow without a line code. | ||
3. Better user experience | ||
|
||
## How gob works | ||
|
@@ -171,6 +171,22 @@ List all the installed plugins | |
|
||
### gob setup version | ||
|
||
|
||
## FAQ | ||
|
||
- [When install a plugin, how to find out the url?](#) | ||
|
||
`gob plugin install` work the same way as `go install`, it take the same url as `go install`. | ||
|
||
|
||
- [How to upgrade a plugin ?](#) | ||
|
||
Just simply edit `gob.yaml` file and update the version you want. | ||
```yaml | ||
plugins: | ||
golangci-lint: | ||
alias: lint | ||
args: run ./... | ||
url: github.com/golangci/golangci-lint/cmd/[email protected] | ||
``` | ||
` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
Copyright © 2023 kcmvp <[email protected]> | ||
*/ | ||
package cmd | ||
|
||
|
@@ -28,21 +28,9 @@ func builtinPlugins() []internal.Plugin { | |
return plugins | ||
} | ||
|
||
func initBuildVersion() { | ||
infra := filepath.Join(internal.CurProject().Root(), "infra") | ||
if _, err := os.Stat(infra); err != nil { | ||
os.Mkdir(infra, 0700) // nolint | ||
} | ||
ver := filepath.Join(infra, "version.go") | ||
if _, err := os.Stat(ver); err != nil { | ||
data, _ := resources.ReadFile(filepath.Join(resourceDir, "version.tmpl")) | ||
os.WriteFile(ver, data, 0666) //nolint | ||
} | ||
} | ||
|
||
func initializerFunc(_ *cobra.Command, _ []string) { | ||
fmt.Println("Initialize configuration ......") | ||
initBuildVersion() | ||
// initBuildVersion() | ||
lo.ForEach(builtinPlugins(), func(plugin internal.Plugin, index int) { | ||
internal.CurProject().SetupPlugin(plugin) | ||
if len(plugin.Config) > 0 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"github.com/samber/lo" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// setupCmd represents the setup command | ||
var setupCmd = &cobra.Command{ | ||
Use: "setup", | ||
Short: "Setup scaffold of Go project", | ||
Long: `Setup scaffold for most common used frameworks`, | ||
ValidArgs: func() []string { | ||
return lo.Map(setupActions(), func(action Action, _ int) string { | ||
return action.A | ||
}) | ||
}(), | ||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
action, _ := lo.Find(setupActions(), func(action Action) bool { | ||
return action.A == args[0] | ||
}) | ||
_ = action.B(cmd, args...) | ||
}, | ||
} | ||
|
||
func init() { | ||
builderCmd.AddCommand(setupCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/kcmvp/gob/internal" | ||
"github.com/stretchr/testify/assert" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestValidSetupArgs(t *testing.T) { | ||
assert.Equal(t, setupCmd.ValidArgs, []string{"version"}) | ||
} | ||
|
||
func TestSetupVersion(t *testing.T) { | ||
version := filepath.Join(internal.CurProject().Root(), "infra", "version.go") | ||
os.Remove(version) | ||
_, err := os.Stat(version) | ||
assert.Error(t, err) | ||
builderCmd.SetArgs([]string{"setup", "version"}) | ||
err = builderCmd.Execute() | ||
assert.NoError(t, err) | ||
_, err = os.Stat(version) | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters