Skip to content

Commit

Permalink
Merge pull request bruin-data#144 from bruin-data/patch/add-version
Browse files Browse the repository at this point in the history
Patch/add version
  • Loading branch information
albertobruin authored Nov 4, 2024
2 parents 7bf08c6 + 97f626c commit ca11011
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,48 @@ package main

import (
"fmt"
"net/http"
"os"
"runtime/debug"
"strings"
"time"

"github.com/bruin-data/bruin/cmd"
"github.com/fatih/color"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)

var Version = "development"
var (
version = "dev"
commit = ""
)

func main() {
isDebug := false
color.NoColor = false

cli.VersionPrinter = func(cCtx *cli.Context) {
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
hash := commit
if hash == "" {
hash = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
}
return ""
}()
return ""
}()
}

fmt.Printf("bruin CLI %s (%s)\n", cCtx.App.Version, commit)
fmt.Printf("bruin CLI %s (%s)\n", cCtx.App.Version, hash)
}

app := &cli.App{
Name: "bruin",
Version: Version,
Version: version,
Usage: "The CLI used for managing Bruin-powered data pipelines",
Compiled: time.Now(),
Flags: []cli.Flag{
Expand All @@ -57,6 +66,20 @@ func main() {
cmd.Environments(&isDebug),
cmd.Connections(),
cmd.Fetch(),
&cli.Command{
Name: "version",
Action: func(c *cli.Context) error {
fmt.Printf("Current version: %s (%s)\n", c.App.Version, commit)
res, err := http.Get("https://github.com/bruin-data/bruin/releases/latest") //nolint
defer res.Body.Close() //nolint
if err != nil {
return errors.Wrap(err, "failed to check the latest version")
}

fmt.Println("Latest version: " + strings.TrimPrefix(res.Request.URL.String(), "https://github.com/bruin-data/bruin/releases/tag/"))
return nil
},
},
},
}

Expand Down

0 comments on commit ca11011

Please sign in to comment.