Skip to content

Commit

Permalink
fix(Version): Fixed the version cmd
Browse files Browse the repository at this point in the history
- improved way of displaying data
- added the option to verify against the github repo if that is the latest version
- the go.mod is cleaned

BREAKING CHANGE: No

Signed-off-by: Alejandro JNM <[email protected]>
  • Loading branch information
alejandrojnm committed May 13, 2020
1 parent 3ecf80b commit f01cff8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 193 deletions.
35 changes: 25 additions & 10 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,49 @@ package cmd

import (
"fmt"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
goVersion "go.hein.dev/go-version"
"github.com/tcnksm/go-latest"
"runtime"
"strings"
)

var (
shortened = false
quiet = false
VersionCli = "dev"
CommitCli = "none"
DateCli = "unknown"
versionCmd = &cobra.Command{
Use: "version",
Short: "Version will output the current build information",
Run: func(cmd *cobra.Command, args []string) {
var response string
versionOutput := goVersion.New(VersionCli, CommitCli, DateCli)

if shortened {
response = versionOutput.ToShortened()
githubTag := &latest.GithubTag{
Owner: "civo",
Repository: "cli-go",
FixVersionStrFunc: latest.DeleteFrontV(),
}
res, _ := latest.Check(githubTag, strings.Replace(VersionCli, "v", "", 1))

if !quiet {
fmt.Printf("Client version: %s\n", VersionCli)
fmt.Printf("Go version (client): %s\n", runtime.Version())
fmt.Printf("Git commit (client): %s\n", CommitCli)
fmt.Printf("OS/Arch (client): %s/%s\n", runtime.GOOS, runtime.GOARCH)

if res.Outdated {
utility.YellowConfirm("A newer version (v%s) is available, please upgrade\n", res.Current)
}

} else {
response = versionOutput.ToJSON()
fmt.Printf("%s\n", VersionCli)
}
fmt.Printf("%+v", response)
return

},
}
)

func init() {
rootCmd.AddCommand(versionCmd)
versionCmd.Flags().BoolVarP(&shortened, "short", "s", false, "Use shortened output for version information.")
versionCmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "Use quiet output for version information.")
}
18 changes: 5 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,19 @@ go 1.13
module github.com/civo/cli

require (
github.com/ajg/form v1.5.1 // indirect
github.com/briandowns/spinner v1.9.0
github.com/civo/civogo v0.2.8
github.com/fatih/color v1.9.0
github.com/google/go-github v17.0.0+incompatible // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75
github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d // indirect
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381
github.com/hashicorp/go-version v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/olekukonko/tablewriter v0.0.3
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.4.0
go.hein.dev/go-version v0.1.0
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/tools v0.0.0-20191126055441-b0650ceb63d9 // indirect
gopkg.in/ini.v1 v1.51.1 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
Loading

0 comments on commit f01cff8

Please sign in to comment.