Giter VIP home page Giter VIP logo

upgrade-cli's Introduction

UpgradeCLI

UpgradeCLI makes it easy to add an upgrade command to your cli.

UpgradeCLI was built to implement the upgrade command for Savvy's OSS CLI.

Savvy's CLI helps developers create and share high quality runbooks right from the terminal.

Install

go get github.com/getsavvyinc/upgrade-cli

Usage

package cmd

import (
	"context"
	"os"

	"github.com/getsavvyinc/savvy-cli/config"
	"github.com/getsavvyinc/savvy-cli/display"
	"github.com/getsavvyinc/upgrade-cli"
	"github.com/spf13/cobra"
)

const owner = "getsavvyinc"
const repo = "savvy-cli"

// upgradeCmd represents the upgrade command
var upgradeCmd = &cobra.Command{
	Use:   "upgrade",
	Short: "upgrade savvy to the latest version",
	Long:  `upgrade savvy to the latest version`,
	Run: func(cmd *cobra.Command, args []string) {
		executablePath, err := os.Executable()
		if err != nil {
			display.Error(err)
			os.Exit(1)
		}
		version := config.Version()

		upgrader := upgrade.NewUpgrader(owner, repo, executablePath)

		if ok, err := upgrader.IsNewVersionAvailable(context.Background(), version); err != nil {
			display.Error(err)
			return
		} else if !ok {
			display.Info("Savvy is already up to date")
			return
		}

		display.Info("Upgrading savvy...")
		if err := upgrader.Upgrade(context.Background(), version); err != nil {
			display.Error(err)
			os.Exit(1)
		} else {
			display.Success("Savvy has been upgraded to the latest version")
		}
	},
}

func init() {
	rootCmd.AddCommand(upgradeCmd)
}

Requirements

upgrade-cli is fully compatible with releases generated using goreleaser.

upgrade-cli makes the following assumptions about Relase Assets.

  • The checksum file has a checksums.txt suffix
  • The checksum file format matches the example below:
6796a0fb64d0c78b2de5410a94749a3bfb77291747c1835fbd427e8bf00f6af3  savvy_darwin_arm64
3853c410eeee629f71a981844975700b2925ac7582bf5559c384c391be8abbcb  savvy_darwin_x86_64
00637eae6cf7588d990d64113a02caca831ea5391ef6f66c88db2dfa576ca6bd  savvy_linux_arm64
1e9c98dbb0f54ee06119d957fa140b42780aa330d11208ad0a21c2a06832eca3  savvy_linux_i386
3040ff4c07dda6c7ff65f9476b57277b14a72d0b33381b35aa8810df3e1785ea  savvy_linux_x86_64
  • The URL to download a binary asset for a particular $os, $arch ends with $os_$arch

Contributing

All contributions are welcome - bug reports, pull requests and ideas for improving the package.

  1. Join the #upgrade-cli channel on Discord
  2. Open an issue on GitHub to reports bugs or feature requests
  3. Please follow a "fork and pull request" workflow for submitting changes to the repository.

upgrade-cli's People

Contributors

joshi4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.