diff --git a/README.md b/README.md index ace41b5..264811b 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,5 @@ Advanced settings can be provided via a top level json key named "config". Here | Key | Example Value | Description | |---------------|---------------|---------------------------| | key-order | "Column3,Column1,Column2"| Comma separated list of column names in the desired order | -| overwrite-file | true | Boolean indicating whether output file should be overwritten if it already exists | \ No newline at end of file +| overwrite-file | true | Boolean indicating whether output file should be overwritten if it already exists | +| parent-node | "results" | Specify an alternate starting key for the spreadsheet data than just the first non-config key. Useful with json structures with multiple top-level keys | \ No newline at end of file diff --git a/cmd/main/main.go b/cmd/main/main.go index 0869527..0e6f9ef 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -18,7 +18,8 @@ import ( // Initial concept from https://stackoverflow.com/q/68621039 type Config struct { - keyOrder map[int]string + keyOrder map[int]string + parentOverride string } var config Config @@ -99,6 +100,7 @@ func main() { } // Get an interface that we can work with to access the sub elements + // This doesn't seem necessary for some reason - maybe because there's only one level of depth to the configNode //configSlice := configInterface //fmt.Printf("%v\n", configSlice) @@ -119,6 +121,10 @@ func main() { fmt.Printf("Found config element for overwriting output file\n") e, _ := configMap.Get(key) overwriteFile = e.(bool) + } else if strings.EqualFold(key, "parent-node") { + fmt.Printf("Found config element for forcing parent key for spreadsheet data\n") + e, _ := configMap.Get(key) + config.parentOverride = e.(string) } } } else if strings.EqualFold(topLevel[0], configNode) { @@ -129,6 +135,11 @@ func main() { parentNode = topLevel[0] } + if config.parentOverride != "" { + fmt.Printf("Overriding parent node to '%s'\n", config.parentOverride) + parentNode = config.parentOverride + } + // Get a reference to the top level node we specified earlier vislice, ok := o.Get(parentNode) if !ok {