@@ -2,39 +2,48 @@ package main
2
2
3
3
import (
4
4
"fmt"
5
+ "net/http"
5
6
"os"
6
7
"runtime/debug"
8
+ "strings"
7
9
"time"
8
10
9
11
"github.com/bruin-data/bruin/cmd"
10
12
"github.com/fatih/color"
13
+ "github.com/pkg/errors"
11
14
"github.com/urfave/cli/v2"
12
15
)
13
16
14
- var Version = "development"
17
+ var (
18
+ version = "dev"
19
+ commit = ""
20
+ )
15
21
16
22
func main () {
17
23
isDebug := false
18
24
color .NoColor = false
19
25
20
26
cli .VersionPrinter = func (cCtx * cli.Context ) {
21
- var commit = func () string {
22
- if info , ok := debug .ReadBuildInfo (); ok {
23
- for _ , setting := range info .Settings {
24
- if setting .Key == "vcs.revision" {
25
- return setting .Value
27
+ hash := commit
28
+ if hash == "" {
29
+ hash = func () string {
30
+ if info , ok := debug .ReadBuildInfo (); ok {
31
+ for _ , setting := range info .Settings {
32
+ if setting .Key == "vcs.revision" {
33
+ return setting .Value
34
+ }
26
35
}
27
36
}
28
- }
29
- return ""
30
- }()
37
+ return ""
38
+ }()
39
+ }
31
40
32
- fmt .Printf ("bruin CLI %s (%s)\n " , cCtx .App .Version , commit )
41
+ fmt .Printf ("bruin CLI %s (%s)\n " , cCtx .App .Version , hash )
33
42
}
34
43
35
44
app := & cli.App {
36
45
Name : "bruin" ,
37
- Version : Version ,
46
+ Version : version ,
38
47
Usage : "The CLI used for managing Bruin-powered data pipelines" ,
39
48
Compiled : time .Now (),
40
49
Flags : []cli.Flag {
@@ -57,6 +66,20 @@ func main() {
57
66
cmd .Environments (& isDebug ),
58
67
cmd .Connections (),
59
68
cmd .Fetch (),
69
+ & cli.Command {
70
+ Name : "version" ,
71
+ Action : func (c * cli.Context ) error {
72
+ fmt .Printf ("Current version: %s (%s)\n " , c .App .Version , commit )
73
+ res , err := http .Get ("https://github.com/bruin-data/bruin/releases/latest" ) //nolint
74
+ defer res .Body .Close () //nolint
75
+ if err != nil {
76
+ return errors .Wrap (err , "failed to check the latest version" )
77
+ }
78
+
79
+ fmt .Println ("Latest version: " + strings .TrimPrefix (res .Request .URL .String (), "https://github.com/bruin-data/bruin/releases/tag/" ))
80
+ return nil
81
+ },
82
+ },
60
83
},
61
84
}
62
85
0 commit comments