-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(go-code/bump-version): Add shortcut for bump version of SL go ap…
…plications
- Loading branch information
1 parent
e59f54a
commit ff3e3f6
Showing
5 changed files
with
151 additions
and
3 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
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,15 @@ | ||
package go_code | ||
|
||
import ( | ||
"github.com/sikalabs/slu/cmd/root" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "go-code", | ||
Short: "Utils for writing Go code", | ||
} | ||
|
||
func init() { | ||
root.RootCmd.AddCommand(Cmd) | ||
} |
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,57 @@ | ||
package version_bump | ||
|
||
import ( | ||
"io/ioutil" | ||
|
||
"github.com/go-git/go-git/v5" | ||
go_code_cmd "github.com/sikalabs/slu/cmd/go_code" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var CmdFlagVersion string | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "version-bump", | ||
Short: "Bumb & commit version of (SL) Go application", | ||
Args: cobra.NoArgs, | ||
Run: func(c *cobra.Command, args []string) { | ||
version_go_file := `package version | ||
var Version string = "` + CmdFlagVersion + `" | ||
` | ||
err := ioutil.WriteFile("version/version.go", []byte(version_go_file), 0644) | ||
if err != nil { | ||
panic(err) | ||
} | ||
r, err := git.PlainOpen(".") | ||
if err != nil { | ||
panic(err) | ||
} | ||
w, err := r.Worktree() | ||
if err != nil { | ||
panic(err) | ||
} | ||
_, err = w.Add("version/version.go") | ||
if err != nil { | ||
panic(err) | ||
} | ||
commit, _ := w.Commit("VERSION "+CmdFlagVersion, &git.CommitOptions{}) | ||
_, err = r.CommitObject(commit) | ||
if err != nil { | ||
panic(err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
go_code_cmd.Cmd.AddCommand(Cmd) | ||
Cmd.Flags().StringVarP( | ||
&CmdFlagVersion, | ||
"version", | ||
"v", | ||
"", | ||
"New version", | ||
) | ||
Cmd.MarkFlagRequired("version") | ||
} |
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
Oops, something went wrong.