8000 Fix updater · sargath/symfony-cli@de8827d · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit de8827d

Browse files
committed
Fix updater
1 parent 2a80dc0 commit de8827d

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

updater/updater.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/hashicorp/go-version"
1616
"github.com/pkg/errors"
1717
"github.com/rs/zerolog"
18+
"github.com/symfony-cli/console"
1819
"github.com/symfony-cli/symfony-cli/util"
1920
)
2021

@@ -51,10 +52,16 @@ type Updater struct {
5152
// CheckForNewVersion does a simple check once (within the Updater.Timeout
5253
// timeframe) for new version available and display a warning if
5354
// a new version is found.
54-
func (updater *Updater) CheckForNewVersion(currentVersion string) {
55+
func (updater *Updater) CheckForNewVersion(currentVersionStr string) {
5556
if util.IsGoRun< 8000 /span>() {
5657
return
5758
}
59+
60+
currentVersion, err := version.NewVersion(currentVersionStr)
61+
if err != nil {
62+
return
63+
}
64+
5865
newVersionCh := make(chan *version.Version)
5966
go func() {
6067
version := updater.check(currentVersion, true)
@@ -74,9 +81,9 @@ func (updater *Updater) CheckForNewVersion(currentVersion string) {
7481
updater.silence()
7582
return
7683
}
77-
fmt.Fprintf(updater.Output, "\n<warning>INFO</> A new version is available (<info>%s</>, currently running <info>%s</>).\n\n", newVersionFound, currentVersion)
78-
fmt.Fprintf(updater.Output, " <info>Consider upgrading soon by downloading the new version:</> <href=https://github.com/symfony-cli/symfony-cli/releases>https://github.com/symfony-cli/symfony-cli/releases</>\n")
79-
fmt.Fprintf(updater.Output, " And then, replace the current binary by the new one.\n\n")
84+
fmt.Fprintf(updater.Output, "\n<error> INFO </> <info>A new Symfony CLI version is available</> (<info>%s</>, currently running <info>%s</>).\n\n", newVersionFound, currentVersion)
85+
fmt.Fprintf(updater.Output, " Upgrade soon by downloading the new version at <href=https://github.com/symfony-cli/symfony-cli/releases>https://github.com/symfony-cli/symfony-cli/releases</>\n")
86+
fmt.Fprintf(updater.Output, " And replace the current binary (<info>%s</>) by the new one.\n\n", console.CurrentBinaryName())
8087
}
8188
}
8289

@@ -87,7 +94,7 @@ func (updater *Updater) silence() {
8794
}
8895
}
8996

90-
func (updater *Updater) check(currentVersion string, enableCache bool) *version.Version {
97+
func (updater *Updater) check(currentVersion *version.Version, enableCache bool) *version.Version {
9198
if err := updater.createCacheDir(); err != nil {
9299
fmt.Fprintf(updater.Output, "<comment>Disabling update check: %q</>\n", err)
93100
return nil
@@ -163,12 +170,16 @@ func (updater *Updater) check(currentVersion string, enableCache bool) *version.
163170
updater.logger.Err(err).Msg("")
164171
return nil
165172
}
166-
version, err := version.NewVersion(manifest.Name)
173+
174+
latestVersion, err := version.NewVersion(manifest.Name)
167175
if err != nil {
168176
updater.logger.Err(err).Msg("")
169177
return nil
170178
}
171-
return version
179+
if latestVersion.GreaterThan(currentVersion) {
180+
return latestVersion
181+
}
182+
return nil
172183
}
173184

174185
func (updater *Updater) createCacheDir() error {

0 commit comments

Comments
 (0)
0