From 9bceea24388272e8950dfc51583108764e13bfa5 Mon Sep 17 00:00:00 2001 From: den-rgb Date: Tue, 12 Nov 2024 17:05:04 +0000 Subject: [PATCH] OCM-12479 | fix: Fixed help message for binary builds --- cmd/create/network/cmd.go | 84 +++++++++++++++++++++++------------ pkg/options/network/create.go | 14 ++++-- 2 files changed, 66 insertions(+), 32 deletions(-) diff --git a/cmd/create/network/cmd.go b/cmd/create/network/cmd.go index 30a057b6b..70d2a0f6a 100644 --- a/cmd/create/network/cmd.go +++ b/cmd/create/network/cmd.go @@ -28,40 +28,68 @@ func NewNetworkCommand() *cobra.Command { cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { templateDir := options.TemplateDir - err := filepath.WalkDir(templateDir, func(path string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - if !d.IsDir() && strings.HasSuffix(d.Name(), ".yaml") { - templateBody, err := os.ReadFile(path) - if err != nil { - fmt.Println(err) - return nil - } + var templateBody []byte + var err error - var templateMap map[string]interface{} - err = yaml.Unmarshal(templateBody, &templateMap) + if options.TemplateDir == opts.DefaultTemplateDir { + templateBody = []byte(CloudFormationTemplateFile) + } else { + err = filepath.WalkDir(templateDir, func(path string, d fs.DirEntry, err error) error { if err != nil { - fmt.Println(err) - return nil + return err } - - parameters, ok := templateMap["Parameters"].(map[string]interface{}) - if !ok { - fmt.Printf("No parameters found in the CloudFormation template %s\n", d.Name()) - return nil + if !d.IsDir() && strings.HasSuffix(d.Name(), ".yaml") { + templateBody, err = os.ReadFile(path) + if err != nil { + fmt.Println(err) + return nil + } + + var templateMap map[string]interface{} + err = yaml.Unmarshal(templateBody, &templateMap) + if err != nil { + fmt.Println(err) + return nil + } + + parameters, ok := templateMap["Parameters"].(map[string]interface{}) + if !ok { + fmt.Printf("No parameters found in the CloudFormation template %s\n", d.Name()) + return nil + } + + fmt.Printf("Available parameters in %s/%s:\n", filepath.Base(filepath.Dir(path)), d.Name()) + for paramName := range parameters { + fmt.Printf(" %s\n", paramName) + } + fmt.Printf(" %s\n", "Tags") } + return nil + }) + if err != nil { + fmt.Println(err) + } + } - fmt.Printf("Available parameters in %s/%s:\n", filepath.Base(filepath.Dir(path)), d.Name()) - for paramName := range parameters { - fmt.Printf(" %s\n", paramName) - } - fmt.Printf(" %s\n", "Tags") + if options.TemplateDir == opts.DefaultTemplateDir { + var templateMap map[string]interface{} + err = yaml.Unmarshal(templateBody, &templateMap) + if err != nil { + fmt.Println(err) + return } - return nil - }) - if err != nil { - fmt.Println(err) + + parameters, ok := templateMap["Parameters"].(map[string]interface{}) + if !ok { + fmt.Printf("No parameters found in the default CloudFormation template\n") + return + } + + fmt.Printf("Available parameters in default template:\n") + for paramName := range parameters { + fmt.Printf(" %s\n", paramName) + } + fmt.Printf(" %s\n", "Tags") } fmt.Println("\n" + cmd.UsageString()) diff --git a/pkg/options/network/create.go b/pkg/options/network/create.go index e33ced52e..2b10a48ac 100644 --- a/pkg/options/network/create.go +++ b/pkg/options/network/create.go @@ -19,8 +19,14 @@ const ( "\n" + ` rosa create network rosa-quickstart-default-vpc --param Region=us-west-2` + ` --param Name=quickstart-stack --param AvailabilityZoneCount=1 --param VpcCidr=10.0.0.0/16` + "\n\n" + ` # To delete the AWS cloudformation stack` + - "\n" + ` aws cloudformation delete-stack --stack-name --region ` - defaultTemplateDir = "cmd/create/network/templates" + "\n" + ` aws cloudformation delete-stack --stack-name --region ` + + "\n\n" + `# TEMPLATE_NAME:` + + "\n" + `Specifies the name of the template to use. This should match the name of a directory ` + + "\n" + `under the path specified by '--template-dir' or the 'OCM_TEMPLATE_DIR' environment variable.` + + "\n" + `The directory should contain a YAML file defining the custom template structure.` + + "\n\n" + `If no TEMPLATE_NAME is provided, or if no matching directory is found, the default ` + + "\n" + `built-in template 'rosa-quickstart-default-vpc' will be used.` + DefaultTemplateDir = "cmd/create/network/templates" ) type NetworkUserOptions struct { @@ -44,7 +50,7 @@ func NewNetworkUserOptions() *NetworkUserOptions { } options.TemplateDir = templateDir } else { - options.TemplateDir = defaultTemplateDir + options.TemplateDir = DefaultTemplateDir } return options @@ -84,7 +90,7 @@ func BuildNetworkCommandWithOptions() (*cobra.Command, *NetworkUserOptions) { flags.StringVar( &options.TemplateDir, "template-dir", - defaultTemplateDir, + DefaultTemplateDir, "Use a specific template directory, overriding the OCM_TEMPLATE_DIR environment variable.", ) flags.StringArrayVar(