~robertgzr/yamlfs

080a9313581b8964903c7146319959c3fd811ee8 — Robert Günzler 2 years ago d74b9d5 0.6.1
Fix defined/required reconciliation
2 files changed, 12 insertions(+), 13 deletions(-)

M cmd/yamlfs/helpers.go
M cmd/yamlfs/main.go
M cmd/yamlfs/helpers.go => cmd/yamlfs/helpers.go +10 -10
@@ 23,15 23,13 @@ func makeTempCopy(fpath string) (tmppath string, err error) {
}

func checkVariables(tpls *template.Template, defined map[string]string) map[string]string {
	variables := make(map[string]string)
	variables := make(map[string]string, len(defined))
	for k, v := range defined {
		variables[k] = v
	}
	for _, t := range tpls.Templates() {
		checkNodes(t.Tree.Root.Nodes, variables, false)
	}
	for key := range variables {
		if val, ok := defined[key]; ok {
			variables[key] = val
		}
	}
	return variables
}



@@ 46,12 44,12 @@ func checkNode(node parse.Node, variables map[string]string, inv bool) {
	case parse.NodeField:
		node := node.(*parse.FieldNode)
		for _, field := range node.Ident {
			_, ok := variables[field]
			val, ok := variables[field]
			if !ok && !inv {
				log.Printf("adding %q to %v", field, variables)
				variables[field] = ""
			}
			if ok && inv {
			if ok && val == "" && inv {
				log.Printf("removing %q from %v", field, variables)
				delete(variables, field)
			}


@@ 66,8 64,10 @@ func checkNode(node parse.Node, variables map[string]string, inv bool) {
					// try to parse the default value
					if c.Args[2].Type() == parse.NodeField {
						key := c.Args[2].(*parse.FieldNode).Ident[0]
						variables[key] = strings.Trim(c.Args[1].String(), "\"")
						log.Println(variables[key])
						if _, ok := variables[key]; !ok {
							variables[key] = strings.Trim(c.Args[1].String(), "\"")
							log.Printf("default %q to %q", key, variables[key])
						}
					}
				}
			}

M cmd/yamlfs/main.go => cmd/yamlfs/main.go +2 -3
@@ 81,10 81,9 @@ func main() {
		os.Exit(1)
	}

	variables := checkVariables(tpl, tplLiteral)
	undefinedVariables := checkVariables(tpl, tplLiteral)
	// FIXME this should consider `limits`
	undefinedVariables := variables
	for key, val := range variables {
	for key, val := range undefinedVariables {
		log.Printf("%q: %q", key, val)
		defined := false
		if val != "" && val != "-" {