@@ -22,7 +22,7 @@ import (
22
22
"cdr.dev/coder-cli/pkg/clog"
23
23
"golang.org/x/xerrors"
24
24
25
- "github.com/blang /semver/v4 "
25
+ "github.com/Masterminds /semver/v3 "
26
26
"github.com/manifoldco/promptui"
27
27
"github.com/spf13/afero"
28
28
"github.com/spf13/cobra"
@@ -116,15 +116,15 @@ func (u *updater) Run(ctx context.Context, force bool, coderURLString string) er
116
116
clog .LogInfo (fmt .Sprintf ("Coder instance at %q reports version %s" , coderURL .String (), desiredVersion .String ()))
117
117
clog .LogInfo (fmt .Sprintf ("Current version of coder-cli is %s" , version .Version ))
118
118
119
- if currentVersion , err := semver .Make (u .versionF ()); err == nil {
119
+ if currentVersion , err := semver .StrictNewVersion (u .versionF ()); err == nil {
120
120
if desiredVersion .Compare (currentVersion ) == 0 {
121
121
clog .LogInfo ("Up to date!" )
122
122
return nil
123
123
}
124
124
}
125
125
126
126
if ! force {
127
- label := fmt .Sprintf ("Update coder-cli to version %s" , desiredVersion . FinalizeVersion () )
127
+ label := fmt .Sprintf ("Do you want to download version %s instead " , desiredVersion )
128
128
if _ , err := u .confirmF (label ); err != nil {
129
129
return clog .Fatal ("failed to confirm update" , clog .Tipf (`use "--force" to update without confirmation` ))
130
130
}
@@ -188,7 +188,7 @@ func (u *updater) Run(ctx context.Context, force bool, coderURLString string) er
188
188
return clog .Fatal ("failed to update coder binary in-place" , clog .Causef (err .Error ()))
189
189
}
190
190
191
- clog .LogSuccess ("Updated coder CLI to version " + desiredVersion .FinalizeVersion ())
191
+ clog .LogSuccess ("Updated coder CLI to version " + desiredVersion .String ())
192
192
return nil
193
193
}
194
194
@@ -206,7 +206,18 @@ func makeDownloadURL(version *semver.Version, ostype, archtype string) string {
206
206
default :
207
207
ext = "zip"
208
208
}
209
- return fmt .Sprintf (template , version , ostype , archetype , ext )
209
+ var b bytes.Buffer
210
+ fmt .Fprintf (& b , "%d" , version .Major ())
211
+ fmt .Fprint (& b , "." )
212
+ fmt .Fprintf (& b , "%d" , version .Minor ())
213
+ fmt .Fprint (& b , "." )
214
+ fmt .Fprintf (& b , "%d" , version .Patch ())
215
+ if version .Prerelease () != "" {
216
+ fmt .Fprint (& b , "-" )
217
+ fmt .Fprint (& b , version .Prerelease ())
218
+ }
219
+
220
+ return fmt .Sprintf (template , b .String (), ostype , archtype , ext )
210
221
}
211
222
212
223
func extractFromArchive (path string , archive []byte ) ([]byte , error ) {
@@ -295,22 +306,22 @@ func getCoderConfigURL() (*url.URL, error) {
295
306
296
307
// XXX: coder.Client requires an API key, but we may not be logged into the coder instance for which we
297
308
// want to determine the version. We don't need an API key to sniff the version header.
298
- func getAPIVersionUnauthed (client getter , baseURL url.URL ) (semver.Version , error ) {
309
+ func getAPIVersionUnauthed (client getter , baseURL url.URL ) (* semver.Version , error ) {
299
310
baseURL .Path = path .Join (baseURL .Path , "/api" )
300
311
resp , err := client .Get (baseURL .String ())
301
312
if err != nil {
302
- return semver. Version {} , xerrors .Errorf ("get %s: %w" , baseURL .String (), err )
313
+ return nil , xerrors .Errorf ("get %s: %w" , baseURL .String (), err )
303
314
}
304
315
defer resp .Body .Close ()
305
316
306
317
versionHdr := resp .Header .Get ("coder-version" )
307
318
if versionHdr == "" {
308
- return semver. Version {} , xerrors .Errorf ("URL %s response missing coder-version header" , baseURL .String ())
319
+ return nil , xerrors .Errorf ("URL %s response missing coder-version header" , baseURL .String ())
309
320
}
310
321
311
- version , err := semver .Parse (versionHdr )
322
+ version , err := semver .StrictNewVersion (versionHdr )
312
323
if err != nil {
313
- return semver. Version {} , xerrors .Errorf ("parsing coder-version header: %w" , err )
324
+ return nil , xerrors .Errorf ("parsing coder-version header: %w" , err )
314
325
}
315
326
316
327
return version , nil
0 commit comments