@@ -15,6 +15,7 @@ import (
15
15
"strings"
16
16
17
17
"github.com/AlecAivazis/survey/v2"
18
+ "github.com/Masterminds/semver/v3"
18
19
"github.com/defenseunicorns/pkg/helpers/v2"
19
20
"github.com/defenseunicorns/pkg/oci"
20
21
"github.com/sigstore/cosign/v2/pkg/cosign"
@@ -35,9 +36,11 @@ import (
35
36
"github.com/zarf-dev/zarf/src/types"
36
37
)
37
38
38
- var subAltNames []string
39
- var outputDirectory string
40
- var updateCredsInitOpts types.ZarfInitOptions
39
+ var (
40
+ subAltNames []string
41
+ outputDirectory string
42
+ updateCredsInitOpts types.ZarfInitOptions
43
+ )
41
44
42
45
const (
43
46
registryKey = "registry"
@@ -455,7 +458,9 @@ func (o *clearCacheOptions) run(cmd *cobra.Command, _ []string) error {
455
458
return nil
456
459
}
457
460
458
- type downloadInitOptions struct {}
461
+ type downloadInitOptions struct {
462
+ version string
463
+ }
459
464
460
465
func newDownloadInitCommand () * cobra.Command {
461
466
o := & downloadInitOptions {}
@@ -467,13 +472,24 @@ func newDownloadInitCommand() *cobra.Command {
467
472
}
468
473
469
474
cmd .Flags ().StringVarP (& outputDirectory , "output-directory" , "o" , "" , lang .CmdToolsDownloadInitFlagOutputDirectory )
470
-
475
+ cmd . Flags (). StringVarP ( & o . version , "version" , "v" , o . version , "Specify version to download (defaults to current CLI version)" )
471
476
return cmd
472
477
}
473
478
474
479
func (o * downloadInitOptions ) run (cmd * cobra.Command , _ []string ) error {
475
480
ctx := cmd .Context ()
476
- url := zoci .GetInitPackageURL (config .CLIVersion )
481
+ var url string
482
+
483
+ if o .version == "" {
484
+ url = zoci .GetInitPackageURL (config .CLIVersion )
485
+ } else {
486
+ ver , err := semver .NewVersion (o .version )
487
+ if err != nil {
488
+ return fmt .Errorf ("unable to parse version %s: %w" , o .version , err )
489
+ }
490
+
491
+ url = zoci .GetInitPackageURL (fmt .Sprintf ("v%s" , ver .String ()))
492
+ }
477
493
remote , err := zoci .NewRemote (ctx , url , oci .PlatformForArch (config .GetArch ()))
478
494
if err != nil {
479
495
return fmt .Errorf ("unable to download the init package: %w" , err )
0 commit comments