Skip to content

Commit

Permalink
feat: implement automatic download and install of new version, if ava…
Browse files Browse the repository at this point in the history
…ilable
  • Loading branch information
copernico committed Sep 30, 2020
1 parent ac7100f commit 8f5a767
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
1 change: 0 additions & 1 deletion .github/workflows/license.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ jobs:
steps:
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v1.1

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: detect-private-key
# - id: check-merge-conflict
# - id: detect-private-key
- repo: https://github.com/fsfe/reuse-tool
rev: v0.11.1
hooks:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/sap/project-kb
go 1.13

require (
github.com/blang/semver v3.5.1+incompatible
github.com/blang/semver/v4 v4.0.0
github.com/gin-gonic/contrib v0.0.0-20191209060500-d6e26eeaa607
github.com/gin-gonic/gin v1.6.3
Expand Down
24 changes: 19 additions & 5 deletions kaybee/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"fmt"
"log"

"github.com/blang/semver/v4"
"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
"github.com/spf13/cobra"
)

var forceUpdate bool

var updateCmd = &cobra.Command{
Use: "update",
Short: "Creates a configuration, unless it exists already",
Expand All @@ -25,8 +27,7 @@ each as mergeable or not along with the conflicting slices.

func init() {
rootCmd.AddCommand(updateCmd)
// updateCmd.Flags().BoolVarP(&interactive, "interactive", "i", false, "Interactive configuration")
// updateCmd.Flags().BoolVarP(&force, "force", "f", false, "Force overwrite existing configuration file")
updateCmd.Flags().BoolVarP(&forceUpdate, "force", "f", false, "Upgrade to the latest version, if different from the one in use")
}

func doUpdate(cmd *cobra.Command, args []string) {
Expand All @@ -40,12 +41,25 @@ func doUpdate(cmd *cobra.Command, args []string) {

if ok {
latestSemVer := semver.MustParse(latest.Version.String())

// TESTING
version = "0.0.1"
currentSemVer := semver.MustParse(version)
// currentSemVer := semver.MustParse("0.1.1")

if latestSemVer.Compare(currentSemVer) > 0 {
fmt.Printf("New version detected\n")
fmt.Printf("Newer version detected\n")
fmt.Println("Latest version available: " + latest.Version.String())
fmt.Println("Please download it from: " + latest.URL)
fmt.Println("You are currently using: " + currentSemVer.String())

if forceUpdate {
fmt.Println("Please wait while downloading and upgrading to version " + latest.Version.String())
selfupdate.UpdateSelf(currentSemVer, "sap/project-kb")
fmt.Print("Done upgrading to version " + latest.Version.String())
} else {
fmt.Println("Please download it from: " + latest.URL)
fmt.Println("or run 'kaybee update --force' to download and install automatically.")
}
} else {
fmt.Println("You have the latest version.")
}
Expand Down

0 comments on commit 8f5a767

Please sign in to comment.