mirror of
https://github.com/CyberL1/holesail-proxy.git
synced 2025-02-22 18:19:21 -05:00
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"holesail-proxy/utils"
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var versionCmd = &cobra.Command{
|
|
Use: "version",
|
|
Short: "Displays your CLI version",
|
|
Run: version,
|
|
}
|
|
|
|
var upgradeCmd = &cobra.Command{
|
|
Use: "upgrade",
|
|
Short: "Upgrades your CLI version",
|
|
Run: upgrade,
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(versionCmd)
|
|
versionCmd.AddCommand(upgradeCmd)
|
|
}
|
|
|
|
func version(cmd *cobra.Command, args []string) {
|
|
latestRelease, _ := utils.GetLatestCliVersion()
|
|
|
|
if utils.Version < latestRelease.TagName {
|
|
fmt.Println("A new update is avaliable")
|
|
fmt.Println("Run 'holesail-proxy version upgrade' to upgrade")
|
|
}
|
|
fmt.Println("Your CLI Version:", utils.Version)
|
|
fmt.Println("Latest CLI version:", latestRelease.TagName)
|
|
}
|
|
|
|
func upgrade(cmd *cobra.Command, args []string) {
|
|
var command string
|
|
var cmdArgs []string
|
|
|
|
switch runtime.GOOS {
|
|
case "linux", "darwin":
|
|
command = "sh"
|
|
cmdArgs = []string{"-c", "curl -fsSL https://raw.githubusercontent.com/CyberL1/holesail-proxy/main/scripts/get.sh | sh"}
|
|
|
|
case "windows":
|
|
command = "powershell"
|
|
cmdArgs = []string{"irm https://raw.githubusercontent.com/CyberL1/holesail-proxy/main/scripts/get.ps1 | iex"}
|
|
}
|
|
|
|
execCmd := exec.Command(command, cmdArgs...)
|
|
execCmd.Stderr = os.Stderr
|
|
execCmd.Stdin = os.Stdin
|
|
execCmd.Stdout = os.Stdout
|
|
execCmd.Run()
|
|
}
|