update

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:      "update",
	Short:    "update the executable from github",
	PreRunE:  preUpdate,
	PostRunE: postUpdate,
	Run: func(cmd *cobra.Command, args []string) {
		logger := cmdpkg.InitializeLogger()

		release, err := clientpkg.Release()
		if err != nil {
			logger.Error(err)
			os.Exit(1)
		}

		version, err := semver.ParseTolerant(versionpkg.Version)
		if release.Version.Equals(version) {
			logger.Errorf("current version is the latest")
			os.Exit(0)
		}

		fmt.Print("Do you want to update to ", release.Version, "? (y/n): ")
		scanner := bufio.NewScanner(os.Stdin)
		if !scanner.Scan() {
			logger.Error("failed to scan rune")
			os.Exit(1)
		}
		input := strings.ToLower(scanner.Text())
		if scanner.Err() != nil {
			logger.Errorf("failed to read input: %v", scanner.Err())
			os.Exit(1)
		}

		switch input {
		case "y":
			break
		case "n":
			os.Exit(0)
		default:
			logger.Errorf("Invalid input: %s", input)
			os.Exit(1)
		}

		if err := clientpkg.Update(release); err != nil {
			logger.Errorf("failed to update client: %v", err)
			os.Exit(1)
		}

		logger.Println("Successfully updated to version:", release.Version)

	},
}

Command represents the update command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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