Skip to content

Commit

Permalink
Merge pull request #298 from civo/hotfix/github_version
Browse files Browse the repository at this point in the history
Fix error in the CLI and the GitHub API
  • Loading branch information
alejandrojnm authored Feb 1, 2023
2 parents 020da4f + d9caa77 commit 257b6d1
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 41 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ $(BINARY_WINDOWS): buildprep
buildprep:
git fetch --tags -f
mkdir -p dest
# $(eval VERSION_CLI=$(shell git describe --tags | cut -d "v" -f 2 | cut -d "-" -f 1))
$(eval VERSION_CLI=$(shell git describe --tags | cut -d "v" -f 2 | cut -d "-" -f 1))
$(eval COMMIT_CLI=$(shell git log --format="%H" -n 1))

Expand Down
5 changes: 2 additions & 3 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"runtime"

"github.com/civo/cli/common"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
)

Expand All @@ -24,11 +23,11 @@ var (
fmt.Printf("Build date (client): %s\n", common.DateCli)
fmt.Printf("Git commit (client): %s\n", common.CommitCli)
fmt.Printf("OS/Arch (client): %s/%s\n", runtime.GOOS, runtime.GOARCH)
utility.CheckVersionUpdate()
common.CheckVersionUpdate()
case quiet:
fmt.Printf("v%s\n", common.VersionCli)
default:
utility.CheckVersionUpdate()
common.CheckVersionUpdate()
fmt.Printf("Civo CLI v%s\n", common.VersionCli)
}
},
Expand Down
17 changes: 17 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/google/go-github/github"
"github.com/pkg/errors"
"github.com/tcnksm/go-latest"
"github.com/savioxavier/termlink"
)

var (
Expand All @@ -29,6 +30,22 @@ var (
DateCli = "unknown"
)

// CheckVersionUpdate checks if there's an update to be done
func CheckVersionUpdate() {
res, skip := VersionCheck()
if !skip {
if res.Outdated {
fmt.Printf("A newer version (v%s) is available, please upgrade with \"civo update\"\n", res.Current)
}
}
}

// IssueMessage is the message to be displayed when an error is returned
func IssueMessage() {
gitIssueLink := termlink.ColorLink("GitHub issue", "https://github.com/civo/cli/issues", "italic green")
fmt.Printf("Please check if you are using the latest version of CLI and retry the command \nIf you are still facing issues, please report it on our community slack or open a %s \n", gitIssueLink)
}

// VersionCheck checks if there is a new version of the CLI
func VersionCheck() (res *latest.CheckResponse, skip bool) {
githubTag := &latest.GithubTag{
Expand Down
9 changes: 1 addition & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/civo/civogo"
"github.com/civo/cli/common"
"github.com/gookit/color"
"github.com/mitchellh/go-homedir"
)

Expand Down Expand Up @@ -110,13 +109,7 @@ func loadConfig(filename string) {
fmt.Println(err)
os.Exit(1)
}
res, skip := common.VersionCheck()
if !skip {
if res.Outdated {
msg := "A newer version (v%s) is available, please upgrade with \"civo update\"\n"
fmt.Fprintf(os.Stderr, "%s: %s", color.Red.Sprintf("IMPORTANT"), fmt.Sprintf(msg, res.Current))
}
}
common.CheckVersionUpdate()
}

}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/civo/civogo v0.3.23
github.com/dsnet/compress v0.0.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/google/go-github v17.0.0+incompatible // indirect
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.2.0
github.com/gookit/color v1.3.8
Expand Down
20 changes: 3 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,13 @@ limitations under the License.
package main

import (
"fmt"
"os"
// "fmt"
// "os"

"github.com/civo/cli/cmd"
"github.com/civo/cli/common"
"github.com/savioxavier/termlink"
// "github.com/civo/cli/common"
)

func main() {
defer func() {
if err := recover(); err != nil {
resp, skip := common.VersionCheck()
gitIssueLink := termlink.ColorLink("GitHub issue", "https://github.com/civo/cli/issues", "italic green")
if skip == true {
fmt.Printf("panic : %s \nPlease check if you are using the latest version of CLI and retry the command \nIf you are still facing issues, please report it on our community slack or open a %s \n", err, gitIssueLink)
os.Exit(1)
}
res := resp.Current
updateCmd := "civo update"
fmt.Printf("panic : %s \nYour CLI Version : %s \nPlease, run %q and retry the command \nIf you are still facing issues, please report it on our community slack or open a %s \n", err, res, updateCmd, gitIssueLink)
}
}()
cmd.Execute()
}
12 changes: 1 addition & 11 deletions utility/color_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,9 @@ func Red(value string) string {
return newColor(value)
}

// CheckVersionUpdate checks if there's an update to be done
func CheckVersionUpdate() {
res, skip := common.VersionCheck()
if !skip {
if res.Outdated {
fmt.Printf("A newer version (v%s) is available, please upgrade with \"civo update\"\n", res.Current)
}
}
}

// Error is the function to handler all error in the Cli
func Error(msg string, args ...interface{}) {
CheckVersionUpdate()
common.IssueMessage()
fmt.Fprintf(os.Stderr, "%s: %s\n", color.Red.Sprintf("Error"), fmt.Sprintf(msg, args...))
}

Expand Down

0 comments on commit 257b6d1

Please sign in to comment.