-
-
Notifications
You must be signed in to change notification settings - Fork 70
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 #104 from K-Phoen/self-update
Add self-update command
- Loading branch information
Showing
311 changed files
with
78,351 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blang/semver" | ||
"github.com/rhysd/go-github-selfupdate/selfupdate" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func SelfUpdate(currentVersion string) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "self-update", | ||
Short: "Self-update", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return selfUpdate(currentVersion) | ||
}, | ||
} | ||
} | ||
|
||
func selfUpdate(currentVersion string) error { | ||
current, err := semver.ParseTolerant(currentVersion) | ||
if err != nil { | ||
return fmt.Errorf("could not parse current version: %w", err) | ||
} | ||
|
||
latest, err := selfupdate.UpdateSelf(current, "K-Phoen/grabana") | ||
if err != nil { | ||
return fmt.Errorf("binary update failed: %w", err) | ||
} | ||
|
||
if latest.Version.Equals(current) { | ||
fmt.Printf("Current binary is the latest version: %s\n", currentVersion) | ||
} else { | ||
fmt.Printf("Successfully updated to version %s\n", latest.Version) | ||
} | ||
|
||
return nil | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.