Skip to content

Commit 4c05f4d

Browse files
authored
Fix version (#90)
1 parent 2116c28 commit 4c05f4d

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

cmd/oauth2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type OAuth2Cmd struct {
2727
*cobra.Command
2828
}
2929

30-
func NewOAuth2Cmd() (cmd *OAuth2Cmd) {
30+
func NewOAuth2Cmd(version, commit, date string) (cmd *OAuth2Cmd) {
3131
var cconfig oauth2.ClientConfig
3232

3333
cmd = &OAuth2Cmd{
@@ -40,7 +40,7 @@ func NewOAuth2Cmd() (cmd *OAuth2Cmd) {
4040

4141
cmd.Command.Run = cmd.Run(&cconfig)
4242

43-
cmd.AddCommand(versionCmd)
43+
cmd.AddCommand(NewVersionCmd(version, commit, date))
4444
cmd.AddCommand(docsCmd)
4545

4646
cmd.PersistentFlags().StringVar(&cconfig.RedirectURL, "redirect-url", "http://localhost:9876/callback", "client redirect url")

cmd/oauth2_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (tc *CommandTestCase) Test() func(*testing.T) {
4242
}
4343
}
4444

45-
cmd := NewOAuth2Cmd()
45+
cmd := NewOAuth2Cmd("master", "none", "unknown")
4646
cmd.SetArgs(tc.args)
4747
err := cmd.Execute()
4848

@@ -62,7 +62,7 @@ func (tc *CommandTestCase) GetDeps(t *testing.T) map[string]string {
6262
output := bytes.Buffer{}
6363
result := map[string]interface{}{}
6464

65-
cmd := NewOAuth2Cmd()
65+
cmd := NewOAuth2Cmd("master", "none", "unknown")
6666
cmd.SetArgs(dep.args)
6767
cmd.SetOut(&output)
6868
err := cmd.Execute()

cmd/version.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
package cmd
22

33
import (
4-
"fmt"
5-
"runtime/debug"
6-
74
"github.com/spf13/cobra"
85
)
96

10-
var versionCmd = &cobra.Command{
11-
Use: "version",
12-
Short: "Display version",
13-
Run: func(cmd *cobra.Command, args []string) {
14-
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
15-
fmt.Println(info)
16-
} else {
17-
fmt.Println("unknown")
18-
}
19-
},
7+
func NewVersionCmd(version, commit, date string) *cobra.Command {
8+
return &cobra.Command{
9+
Use: "version",
10+
Short: "Display version",
11+
Run: func(cmd *cobra.Command, args []string) {
12+
cmd.Printf("oauth2c version %s (commit %s, built at %s)\n", version, commit, date)
13+
},
14+
}
2015
}

main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import (
1010
"github.com/pterm/pterm"
1111
)
1212

13+
var (
14+
version = "master"
15+
commit = "none"
16+
date = "unknown"
17+
)
18+
1319
func init() {
1420
c := make(chan os.Signal, 1)
1521
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
@@ -22,7 +28,7 @@ func init() {
2228
}
2329

2430
func main() {
25-
if err := cmd.NewOAuth2Cmd().Execute(); err != nil {
31+
if err := cmd.NewOAuth2Cmd(version, commit, date).Execute(); err != nil {
2632
fmt.Fprintln(os.Stderr, err)
2733
os.Exit(1)
2834
}

0 commit comments

Comments
 (0)