Skip to content

Commit

Permalink
add --check flag to update command
Browse files Browse the repository at this point in the history
  • Loading branch information
ntorresalberto committed Mar 18, 2024
1 parent ef6b731 commit edb57d9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"strings"

"github.com/spf13/cobra"
"syscall"
)

var (
cgoOff = false
checkVersion = false
installCommit = ""
)

Expand Down Expand Up @@ -37,6 +39,10 @@ const updateExamples = `
- Disable CGO in update:
{{.appname}} update --no-cgo
- Check if on the latest version
{{.appname}} update --check
`

var updateCmd = &cobra.Command{
Expand All @@ -55,6 +61,19 @@ Examples:
if installCommit == "" {
installCommit = getCommitHash()
}

if checkVersion {
fmt.Printf("installed version: %s\n", Gray(Version))
fmt.Printf(" github version: %s\n", Gray(installCommit))
if Version != installCommit {
fmt.Printf("update available 🚩\n")
fmt.Printf("use %s\n", Gray(fmt.Sprintf("%s update", appname)))
} else {
fmt.Printf("newest version installed ✅\n")
}
syscall.Exit(0)
}

// fmt.Println("len(installCommit)", len(installCommit))
if len(installCommit) > 8 {
installCommit = installCommit[:8]
Expand Down Expand Up @@ -93,5 +112,6 @@ Examples:
func init() {
rootCmd.AddCommand(updateCmd)
updateCmd.Flags().BoolVar(&cgoOff, "no-cgo", false, "don't use CGO (CGO_ENABLED=0) for go install command")
updateCmd.Flags().BoolVar(&checkVersion, "check", false, "check if there's a newer version available")
updateCmd.Flags().StringVar(&installCommit, "commit", "", "update to specific commit hash or branch. default: latest")
}

0 comments on commit edb57d9

Please sign in to comment.