Skip to content

Commit

Permalink
Merge pull request #23 from camerondurham/feat/upgrade-cmd
Browse files Browse the repository at this point in the history
Minimal implementation for #20
  • Loading branch information
camerondurham authored Nov 20, 2021
2 parents 55cd7e3 + 4820f96 commit 10c98b9
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 20 deletions.
49 changes: 49 additions & 0 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cmd

import (
"fmt"
"github.com/camerondurham/ch/cmd/util"
"github.com/spf13/cobra"
"runtime"
)

// upgradeCmd represents the upgrade command
var upgradeCmd = &cobra.Command{
Use: "upgrade",
Short: "instructions to upgrade the ch cli",
Version: rootCmd.Version,
Run: UpgradeCmd,
}

const UnixUpgradeTerminalCommand = "bash <(curl -s https://raw.githubusercontent.com/camerondurham/ch/main/scripts/install-ch.sh)"
const WindowsUpgradeTerminalCommand = "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/camerondurham/ch/main/scripts/install-ch.ps1'))"

func UpgradeCmd(cmd *cobra.Command, args []string) {

var upgradeCommand string
var os string

switch runtime.GOOS {
case "darwin":
os = "macOS"
fallthrough
case "linux":
// set upgrade command
os = "Linux"
upgradeCommand = UnixUpgradeTerminalCommand
case "windows":
// set upgrade command
os = "Windows"
upgradeCommand = WindowsUpgradeTerminalCommand
}

fmt.Printf("You appear to be running a %s operating system."+
"\nPlease run the following upgrade command:"+
"\n\n %s"+
"\n\nFor more help, see the repository README: %s\n", os, upgradeCommand, util.RepositoryUrl)

}

func init() {
rootCmd.AddCommand(upgradeCmd)
}
8 changes: 3 additions & 5 deletions cmd/util/version_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ func CheckLatestVersion() {
DebugPrint(fmt.Sprintf("ignoring version check since error occured when retrieving latest version: %v\n", err))
} else if version.PkgVersion != "" && latestVersion != version.PkgVersion {
fmt.Printf(
"\tA new version of ch is available!\n"+
"\tYou are running version %s but the latest version is %s.\n"+
"\tSee %s instructions on upgrading.\n",
"\tYou are running version %s but the latest version is %s.\n"+
"\tRun `ch upgrade` for upgrade instructions.\n",
version.PkgVersion,
latestVersion,
RepositoryUrl)
latestVersion)
} else {
DebugPrint(fmt.Sprintf("local package version: %s\nlatest version: %s\n", version.PkgVersion, latestVersion))
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ require (
github.com/containerd/containerd v1.5.8 // indirect
github.com/docker/docker v20.10.8+incompatible
github.com/docker/go-connections v0.4.0
github.com/golang/mock v1.4.4
github.com/golang/mock v1.5.0
github.com/gorilla/mux v1.8.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cast v1.4.0 // indirect
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.1
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 // indirect
google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67 // indirect
Expand Down
Loading

0 comments on commit 10c98b9

Please sign in to comment.