diff --git a/cmd/cloud_init/group/render.go b/cmd/cloud_init/group/render.go index 83175351..af7e2ba9 100644 --- a/cmd/cloud_init/group/render.go +++ b/cmd/cloud_init/group/render.go @@ -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 @@ -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", "e", "", "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 } diff --git a/man/ochami-cloud-init.1.sc b/man/ochami-cloud-init.1.sc index 2fcec2e4..2aebc7c5 100644 --- a/man/ochami-cloud-init.1.sc +++ b/man/ochami-cloud-init.1.sc @@ -13,7 +13,7 @@ ochami cloud-init group delete [OPTIONS] ([-d (_data_ | @_path_)] [-f _format_]) ochami cloud-init group get [OPTIONS] raw [_id_...]++ ochami cloud-init group get [OPTIONS] config [_id_...]++ ochami cloud-init group get [OPTIONS] meta-data [_id_...]++ -ochami cloud-init group render _group_ _id_++ +ochami cloud-init group render ([-e (_extra-variables_ | @_path_)] [-f _format_]) _group_ _id_++ ochami cloud-init group set [OPTIONS]++ ochami cloud-init node get group [OPTIONS] _group_ _id_...++ ochami cloud-init node get meta-data [OPTIONS] _id_...++ @@ -427,6 +427,21 @@ Subcommands for this command are as follows: - */cloud-init/admin/impersonation/{id}/{group}.yaml* - */cloud-init/admin/impersonation/{id}/meta-data* + This command accepts the following options: + + *-e, --extra-vars* (_extra-vars_ | @_path_ | @-) + Specify _extra-vars_ to be passed to the template, the _path_ to a + file to read extra variables from, or to read the extra variables from + standard input (@-). The format of the extra variables read in any of + these forms is JSON by default unless *-f* is specified to change it. + + *-f, --format-input* _format_ + Format of the extra variables being used by *-e*. Supported formats are: + + - _json_ (default) + - _json-pretty_ + - _yaml_ + *set* [-f _format_] < _file_++ *set* [-f _format_] -d @_file_++ *set* [-f _format_] -d @- < _file_++