Skip to content

Commit

Permalink
OCM-12479 | fix: Fixed help message for binary builds
Browse files Browse the repository at this point in the history
  • Loading branch information
den-rgb committed Nov 12, 2024
1 parent b1a0b95 commit 9bceea2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 32 deletions.
84 changes: 56 additions & 28 deletions cmd/create/network/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
14 changes: 10 additions & 4 deletions pkg/options/network/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> --region <region>`
defaultTemplateDir = "cmd/create/network/templates"
"\n" + ` aws cloudformation delete-stack --stack-name <name> --region <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 {
Expand All @@ -44,7 +50,7 @@ func NewNetworkUserOptions() *NetworkUserOptions {
}
options.TemplateDir = templateDir
} else {
options.TemplateDir = defaultTemplateDir
options.TemplateDir = DefaultTemplateDir
}

return options
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9bceea2

Please sign in to comment.