Skip to content

Commit

Permalink
Add --input-root-key parameter
Browse files Browse the repository at this point in the history
pongo2 enforces restrictions on the structure of top level context keys.
This breaks JSON/YAML/other formats if they have regular dashes (-) in
key names. The `--input-root-key` parameter puts the entire input
file context under a common key, which allows it to function normally.
  • Loading branch information
wrouesnel committed Oct 23, 2023
1 parent 5611add commit a3ec87a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/entrypoint/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ type Options struct {
DirectoryMode bool `help:"Treat template path as directory-tree, output path as target directory"`
FilenameSubstrDel string `help:"Delete a given substring in the output filename (only applies to --directory-mode)" name:"directory-mode-filename-substr-del"`

InputRootKey string `help:"If specified, the input will be placed under a common subkey rather then in the root context. Use this when the input may contain invalid root context names."`

Version kong.VersionFlag `help:"Print the version and exit"`
}

Expand Down Expand Up @@ -398,6 +400,12 @@ func Entrypoint(args LaunchArgs) int {
}
}

if options.InputRootKey != "" {
oldInputData := inputData
inputData = make(map[string]interface{})
inputData[options.InputRootKey] = oldInputData
}

if options.DumpInputData {
_, _ = fmt.Fprintln(args.StdErr, inputData)
}
Expand Down

0 comments on commit a3ec87a

Please sign in to comment.