Skip to content

Commit 340512c

Browse files
authored
feat: accept version flag for zarf tools download-init (#3568)
Signed-off-by: Josh Brewer <[email protected]>
1 parent a68da60 commit 340512c

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

site/src/content/docs/commands/zarf_tools_download-init.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ zarf tools download-init [flags]
1919
```
2020
-h, --help help for download-init
2121
-o, --output-directory string Specify a directory to place the init package in.
22+
-v, --version string Specify version to download (defaults to current CLI version)
2223
```
2324

2425
### Options inherited from parent commands

src/cmd/zarf_tools.go

+22-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strings"
1616

1717
"github.com/AlecAivazis/survey/v2"
18+
"github.com/Masterminds/semver/v3"
1819
"github.com/defenseunicorns/pkg/helpers/v2"
1920
"github.com/defenseunicorns/pkg/oci"
2021
"github.com/sigstore/cosign/v2/pkg/cosign"
@@ -35,9 +36,11 @@ import (
3536
"github.com/zarf-dev/zarf/src/types"
3637
)
3738

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+
)
4144

4245
const (
4346
registryKey = "registry"
@@ -455,7 +458,9 @@ func (o *clearCacheOptions) run(cmd *cobra.Command, _ []string) error {
455458
return nil
456459
}
457460

458-
type downloadInitOptions struct{}
461+
type downloadInitOptions struct {
462+
version string
463+
}
459464

460465
func newDownloadInitCommand() *cobra.Command {
461466
o := &downloadInitOptions{}
@@ -467,13 +472,24 @@ func newDownloadInitCommand() *cobra.Command {
467472
}
468473

469474
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)")
471476
return cmd
472477
}
473478

474479
func (o *downloadInitOptions) run(cmd *cobra.Command, _ []string) error {
475480
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+
}
477493
remote, err := zoci.NewRemote(ctx, url, oci.PlatformForArch(config.GetArch()))
478494
if err != nil {
479495
return fmt.Errorf("unable to download the init package: %w", err)

0 commit comments

Comments
 (0)