-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from kool-dev/self-update
Adding self-update command
- Loading branch information
Showing
9 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/blang/semver" | ||
"github.com/rhysd/go-github-selfupdate/selfupdate" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(selfUpdateCmd) | ||
} | ||
|
||
var selfUpdateCmd = &cobra.Command{ | ||
Use: "self-update", | ||
Short: "Update kool to latest version", | ||
Long: "Checks for the latest release of Kool on Github Releases, downloads and replaces the local binary if a newer version is available.", | ||
Run: runSelfUpdate, | ||
Args: cobra.MaximumNArgs(0), | ||
} | ||
|
||
func runSelfUpdate(cmf *cobra.Command, args []string) { | ||
var ( | ||
currentVersion semver.Version | ||
updater *selfupdate.Updater | ||
err error | ||
latest *selfupdate.Release | ||
) | ||
|
||
currentVersion = semver.MustParse(version) | ||
if updater, err = selfupdate.NewUpdater(selfupdate.Config{ | ||
Validator: &selfupdate.SHA2Validator{}, | ||
}); err != nil { | ||
fmt.Println("Failed to create updater controller", err) | ||
os.Exit(1) | ||
} | ||
|
||
if latest, err = updater.UpdateSelf(currentVersion, "kool-dev/kool"); err != nil { | ||
fmt.Println("Kool self-update failed:", err) | ||
os.Exit(1) | ||
} | ||
|
||
if latest.Version.Equals(currentVersion) { | ||
fmt.Println("You already have the latest version.", version) | ||
} else { | ||
fmt.Println("Successfully updated to version", latest.Version) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## kool self-update | ||
|
||
Update kool to latest version | ||
|
||
### Synopsis | ||
|
||
Checks for the latest release of Kool on Github Releases, downloads and replaces the local binary if a newer version is available. | ||
|
||
``` | ||
kool self-update [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for self-update | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kool](kool.md) - kool - Kool stuff | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters