update

package
v0.0.0-...-bf255b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CmdVersion = "1.0.1"
View Source
var UpdateCmd = &cobra.Command{
	Use:   "update",
	Short: "Update CLI if an update is available",
	Run: func(cmd *cobra.Command, args []string) {
		latestVersion, isLatestVersion := CmdIsLatestVersion()
		if isLatestVersion {
			color.Green("Haze is already running at the latest version")
			os.Exit(0)
		}

		path, _ := os.Executable()
		out, err := os.Create(path)
		if err != nil {
			color.Red("Error creating file at %v: %v", path, err.Error())
			os.Exit(1)
		}

		assetFilename := fmt.Sprintf("haze-%v-%v", runtime.GOOS, runtime.GOARCH)
		downloadUrl := fmt.Sprintf("https://github.com/hunoz/haze/releases/download/%v/%v", latestVersion, assetFilename)

		response, err := http.Get(downloadUrl)
		if err != nil {
			color.Red("Error downloading latest version: %v", err.Error())
			os.Exit(1)
		}

		defer response.Body.Close()

		_, err = io.Copy(out, response.Body)
		if err != nil {
			color.Red("Error updating to latest version: %v", err.Error())
		}

		color.Green("Successfully updated Haze to version %v", latestVersion)
	},
}

Functions

func CmdIsLatestVersion

func CmdIsLatestVersion() (string, bool)

Types

type Error

type Error struct {
	Message string `json:"message,omitempty"`
}

type Release

type Release struct {
	Url       string `json:"url,omitempty"`
	AssetsUrl string `json:"assets_url,omitempty"`
	UploadUrl string `json:"upload_url,omitempty"`
	TagName   string `json:"tag_name,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL