From d48e506d325fd8d69d7a9c643e61122adf1a465e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ralph=20K=C3=BChnert?= Date: Sat, 6 Nov 2021 16:04:09 +0100 Subject: [PATCH] interactive value dialog now always in order & removed unnecessary value sorting --- cmd/inputDialog.go | 24 ++++++++++++++++++------ cmd/renderConcept.go | 4 ++++ pkg/concepts/concepts.go | 14 -------------- pkg/concepts/rendering.go | 1 + 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/cmd/inputDialog.go b/cmd/inputDialog.go index 21468b0..1f3af56 100644 --- a/cmd/inputDialog.go +++ b/cmd/inputDialog.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "sort" "github.com/fatih/color" @@ -24,29 +25,40 @@ func (id InputDialog) RunInputDialog() (*concepts.RenderValues, error) { values := concepts.RenderValues{} if len(id.inputs.Mandatory) != 0 { PrintMsg("Mandatory Values") - for id, input := range id.inputs.Mandatory { - value, err := getValue(id, input) + keys := getSortedMapKeys(id.inputs.Mandatory) + for _, key := range keys { + value, err := getValue(key, id.inputs.Mandatory[key]) if err != nil { return nil, err } - values[id] = value + values[key] = value } } if len(id.inputs.Optional) != 0 { PrintMsg("Optional Values") - for id, input := range id.inputs.Optional { - value, err := getValue(id, input) + keys := getSortedMapKeys(id.inputs.Optional) + for _, key := range keys { + value, err := getValue(key, id.inputs.Optional[key]) if err != nil { return nil, err } - values[id] = value + values[key] = value } } return &values, nil } +func getSortedMapKeys(values map[string]concepts.InputType) []string { + var keys []string + for key := range values { + keys = append(keys, key) + } + sort.Strings(keys) + return keys +} + func getValue(name string, input concepts.InputType) (concepts.ValueType, error) { var value concepts.ValueType diff --git a/cmd/renderConcept.go b/cmd/renderConcept.go index d12e048..96c0e91 100644 --- a/cmd/renderConcept.go +++ b/cmd/renderConcept.go @@ -94,14 +94,18 @@ kable render -l . -o out/ if renderinfo != "" { ri, err = concepts.ParseRenderInfoV1FromFile(renderinfo) } else { + PrintMsg("Checking for existing renderinfo.json in output dir...") ri, err = concepts.ParseRenderInfoV1FromFile(filepath.Join(outpath, concepts.ConceptRenderFileName)) } if err != nil { if os.IsNotExist(err) { + PrintMsg(fmt.Sprintf("No existing renderinfo.json detected.")) existingRenderInfo = false } else { PrintError("error parsing existing renderinfo: %s", err) } + } else { + PrintMsg(fmt.Sprintf("Existing renderinfo.json detected at %s/renderinfo.json.", outpath)) } // Ask for values if renderinfo does not exist diff --git a/pkg/concepts/concepts.go b/pkg/concepts/concepts.go index 3d96774..a17b3e9 100644 --- a/pkg/concepts/concepts.go +++ b/pkg/concepts/concepts.go @@ -149,8 +149,6 @@ func (c *Concept) UnmarshalJSON(bytes []byte) error { return err } sort.Strings(inter.Meta.Tags) - sortMapKeys(inter.Inputs.Mandatory) - sortMapKeys(inter.Inputs.Optional) c.ApiVersion = inter.ApiVersion c.Meta = inter.Meta @@ -160,18 +158,6 @@ func (c *Concept) UnmarshalJSON(bytes []byte) error { return nil } -func sortMapKeys(m map[string]InputType) { - keys := make([]string, 0, len(m)) - for k := range m { - keys = append(keys, k) - } - sort.Strings(keys) - - for _, k := range keys { - fmt.Println(k, m[k]) - } -} - type ConceptType string func (ct ConceptType) String() string { diff --git a/pkg/concepts/rendering.go b/pkg/concepts/rendering.go index 67f9b18..22931ec 100644 --- a/pkg/concepts/rendering.go +++ b/pkg/concepts/rendering.go @@ -99,6 +99,7 @@ func ParseRenderInfoV1FromFile(path string) (*RenderInfoV1, error) { } ri := &RenderInfoV1{} + ri.Values = &RenderValues{} if err := json.Unmarshal(f, &ri); err != nil { return nil, err }