Skip to content

Commit

Permalink
Merge pull request #140 from norwoodj/fix/nil-value-types
Browse files Browse the repository at this point in the history
fix: types on nil values
  • Loading branch information
norwoodj authored May 10, 2022
2 parents ef73e2e + 93aef0b commit 88016b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
18 changes: 4 additions & 14 deletions pkg/document/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"regexp"
"strings"

"github.com/norwoodj/helm-docs/pkg/helm"
Expand Down Expand Up @@ -32,9 +31,6 @@ const (
timestampTag = "!!timestamp"
)

var autoDocCommentRegex = regexp.MustCompile("^\\s*#\\s*-- (.*)$")
var nilValueTypeRegex = regexp.MustCompile("^\\(.*?\\)")

func formatNextListKeyPrefix(prefix string, index int) string {
return fmt.Sprintf("%s[%d]", prefix, index)
}
Expand Down Expand Up @@ -81,16 +77,10 @@ func parseNilValueType(key string, description helm.ChartValueDescription, autoD
if len(description.Description) == 0 {
description.Description = autoDescription.Description
}
// Grab whatever's in between the parentheses of the description and treat it as the type
t := nilValueTypeRegex.FindString(description.Description)

if len(t) > 0 {
t = t[1 : len(t)-1]
if len(description.Description) > len(t)+3 {
description.Description = description.Description[len(t)+3:]
} else {
description.Description = ""
}

var t string
if description.ValueType != "" {
t = description.ValueType
} else if autoDescription.ValueType != "" {
// Use whatever the type recognized by autoDescription parser
t = autoDescription.ValueType
Expand Down
10 changes: 5 additions & 5 deletions pkg/document/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,10 @@ animals:
`)

descriptions := map[string]helm.ChartValueDescription{
"animals.birdCount": {Description: "(int) the number of birds we have"},
"animals.birds": {Description: "(list) the list of birds we have"},
"animals.birdCount": {ValueType: intType, Description: "the number of birds we have"},
"animals.birds": {ValueType: listType, Description: "the list of birds we have"},
"animals.nonWeirdCats": {Description: "the cats that we have that are not weird"},
"animals.undescribedCount": {Description: "(int)"},
"animals.undescribedCount": {ValueType: intType, Description: ""},
}

valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)
Expand Down Expand Up @@ -999,8 +999,8 @@ animals:
`)

descriptions := map[string]helm.ChartValueDescription{
"animals.birdCount": {Description: "(int) the number of birds we have", Default: "some"},
"animals.birds": {Description: "(list) the list of birds we have", Default: "explicit"},
"animals.birdCount": {ValueType: intType, Description: "the number of birds we have", Default: "some"},
"animals.birds": {ValueType: listType, Description: "the list of birds we have", Default: "explicit"},
"animals.nonWeirdCats": {Description: "the cats that we have that are not weird", Default: "default"},
}

Expand Down

0 comments on commit 88016b1

Please sign in to comment.