Skip to content

Commit

Permalink
interactive value dialog now always in order & removed unnecessary va…
Browse files Browse the repository at this point in the history
…lue sorting
  • Loading branch information
redradrat committed Nov 6, 2021
1 parent f8aa0f2 commit d48e506
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
24 changes: 18 additions & 6 deletions cmd/inputDialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"sort"

"github.com/fatih/color"

Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cmd/renderConcept.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions pkg/concepts/concepts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/concepts/rendering.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d48e506

Please sign in to comment.