This repository has been archived by the owner on Aug 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
128 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ go.work | |
# Binaries | ||
bin | ||
dist/ | ||
|
||
azctx |
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
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,34 @@ | ||
package pkg | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"go.szostok.io/version" | ||
"go.szostok.io/version/term" | ||
"go.szostok.io/version/upgrade" | ||
) | ||
|
||
func CheckForUpdates(owner, repo string) error { | ||
// Check the current version and print a ghDetector if a new version is available | ||
ghDetector, currentVersion := upgrade.NewGitHubDetector(owner, repo), version.Get().Version | ||
updateCheckInfo, err := ghDetector.LookForLatestRelease(upgrade.LookForLatestReleaseInput{CurrentVersion: currentVersion}) | ||
if err != nil { | ||
return fmt.Errorf("failed to check for updates: %w", err) | ||
} | ||
|
||
if updateCheckInfo.Found { | ||
out, err := ghDetector.Render(updateCheckInfo.ReleaseInfo, term.IsSmart(os.Stderr)) | ||
if err != nil { | ||
return fmt.Errorf("failed to render update notice: %w", err) | ||
} | ||
|
||
_, err = fmt.Fprint(os.Stderr, out) | ||
if err != nil { | ||
return fmt.Errorf("failed to print update notice: %w", err) | ||
} | ||
_, _ = os.Stdout.Write([]byte("\n")) | ||
} | ||
|
||
return nil | ||
} |