Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cmd/cloud_init/group/render.go
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are adding an extra flag here, we'll want to update the render command in the cloud-init(1) manual page with the flag, following the formatting conventions of the commands around it.

Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ See ochami-cloud-init(1) for more details.`,
os.Exit(1)
}
dsWrapper["ds"] = map[string]interface{}{"meta_data": ciData}

// Read any extra variables specified (This is mostly copy-pasted from cli.HandlePayload)
// The primary difference is the flag name
extraVarsMap := make(map[string]interface{})
if cmd.Flag("extra-vars").Changed {
extraVars := cmd.Flag("extra-vars").Value.String()
if err := client.ReadPayload(extraVars, cli.FormatInput, &extraVarsMap); err != nil {
log.Logger.Error().Err(err).Msg("unable to read extra variable data or file")
cli.LogHelpError(cmd)
os.Exit(1)
}
}

// Apply extra variables to the context
for k, v := range extraVarsMap {
dsWrapper[k] = v
}

// Construct the context for the template
refData := exec.NewContext(dsWrapper)

// Render
Expand All @@ -111,5 +130,11 @@ See ochami-cloud-init(1) for more details.`,
},
}

// Create flags
groupRenderCmd.Flags().VarP(&cli.FormatInput, "format-input", "f", "format of input payload data (json,json-pretty,yaml)")
groupRenderCmd.Flags().StringP("extra-vars", "", "", "extra variables to be passed to the template renderer or (if starting with @) file containing extra variables to be passed to the template renderer (can be - to read from stdin)")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should provide a shorthand if using StringP(), otherwise use String(). I would recommend using e as a shorthand flag here.

Also, the description is a bit long. To avoid too much wrapping, could we shorten it? Something like this to eliminate redundancy: "extra variables to be passed to the template renderer or (if starting with @) file containing extra variables (can be - to read from stdin)"


groupRenderCmd.RegisterFlagCompletionFunc("format-input", cli.CompletionFormatData)

return groupRenderCmd
}
Loading