diff --git a/README.md b/README.md index db2292b..9751059 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Available Commands: deploymentAssets Download deployment assets for the given order number at the given cadence name and version - if version not specified, get the latest version of the given cadence name help Help about any command license Download a license for the given order number at the given cadence name and version + getall Download license + certificates + deploymentAssests for the given order number at the given cadence name and version Flags: -c, --config string config file (default is $HOME/.viya4-orders-cli) @@ -206,6 +207,8 @@ using SAS Viya Orders CLI: --config /sasstuff/.viya4-orders-cli.yaml --file-path /sasstuff/sasfiles --file-name 923456_lts_depassets ``` + NOTE: the `--file-name` option is not applicable when using the `getall` command + Sample output: ```text diff --git a/cmd/getall.go b/cmd/getall.go new file mode 100644 index 0000000..83e91d9 --- /dev/null +++ b/cmd/getall.go @@ -0,0 +1,73 @@ +// Copyright © 2020-2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package cmd + +import ( + "log" + "sync" + + "github.com/sassoftware/viya4-orders-cli/lib/assetreqs" + "github.com/spf13/cobra" +) + +// getallCmd represents the getall command +var getallCmd = &cobra.Command{ + Use: "getall [order number] [cadence name] [cadence version]", + Short: "Download all downloadable objects (assets + license + certs) for the given order number at the given cadence name and version ", + Example: "viya4-orders-cli getall 993456 stable 2020.0.3\n" + + "viya4-orders-cli getall 993456 stable 2020.0.3 -p $HOME/sas -n license_993456_stable_2020.0.3", + Aliases: []string{"all"}, + Args: cobra.ExactArgs(3), + Run: func(cmd *cobra.Command, args []string) { + + // check if "file-name" flag is used and if so, log a message this parameter is ignored with the getall command + //if cmd.Flags().Lookup("file-name").Changed { + if assetFileName != "" { + log.Println("The getall command ignores the --file-name option. Default file names will be used instead.") + } + + var wg sync.WaitGroup + var assetTypes []string = []string{"license", "deploymentAssets", "certificates"} + + for _, v := range assetTypes { + + wg.Add(1) + + // cannot reference "v" directly inside func see https://stackoverflow.com/questions/39207608/how-does-golang-share-variables-between-goroutines + // even though it was supposed to work fine in Go 1.22 https://go.dev/blog/go1.22 + go func(assetType string) { + + defer func() { + recover() + wg.Done() + }() + + var p2, p3 string + + switch assetType { + case "certificates": + p2, p3 = "", "" + default: + p2, p3 = args[1], args[2] + } + + ar := assetreqs.New(token, assetType, args[0], p2, p3, assetFilePath, "", outFormat, allowUnsuppd) + err := ar.GetAsset() + if err != nil { + log.Panicln("Error ocurred while getting asset type", assetType, "error is:", err) + } + }(v) + + } + + log.Println("Waiting for downloads to complete.") + wg.Wait() + log.Println("Downloads are complete.") + + }, +} + +func init() { + rootCmd.AddCommand(getallCmd) +}