allow specifying parent-node for data

This commit is contained in:
2023-05-30 16:25:45 +10:00
parent d872cb8517
commit 590d3e3407
2 changed files with 14 additions and 2 deletions

View File

@@ -23,4 +23,5 @@ Advanced settings can be provided via a top level json key named "config". Here
| Key | Example Value | Description | | Key | Example Value | Description |
|---------------|---------------|---------------------------| |---------------|---------------|---------------------------|
| key-order | "Column3,Column1,Column2"| Comma separated list of column names in the desired order | | 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 | | 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 |

View File

@@ -18,7 +18,8 @@ import (
// Initial concept from https://stackoverflow.com/q/68621039 // Initial concept from https://stackoverflow.com/q/68621039
type Config struct { type Config struct {
keyOrder map[int]string keyOrder map[int]string
parentOverride string
} }
var config Config var config Config
@@ -99,6 +100,7 @@ func main() {
} }
// Get an interface that we can work with to access the sub elements // 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 //configSlice := configInterface
//fmt.Printf("%v\n", configSlice) //fmt.Printf("%v\n", configSlice)
@@ -119,6 +121,10 @@ func main() {
fmt.Printf("Found config element for overwriting output file\n") fmt.Printf("Found config element for overwriting output file\n")
e, _ := configMap.Get(key) e, _ := configMap.Get(key)
overwriteFile = e.(bool) 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) { } else if strings.EqualFold(topLevel[0], configNode) {
@@ -129,6 +135,11 @@ func main() {
parentNode = topLevel[0] 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 // Get a reference to the top level node we specified earlier
vislice, ok := o.Get(parentNode) vislice, ok := o.Get(parentNode)
if !ok { if !ok {