Skip to content

Commit 88016b1

Browse files
authored
Merge pull request #140 from norwoodj/fix/nil-value-types
fix: types on nil values
2 parents ef73e2e + 93aef0b commit 88016b1

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

pkg/document/values.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"regexp"
87
"strings"
98

109
"github.com/norwoodj/helm-docs/pkg/helm"
@@ -32,9 +31,6 @@ const (
3231
timestampTag = "!!timestamp"
3332
)
3433

35-
var autoDocCommentRegex = regexp.MustCompile("^\\s*#\\s*-- (.*)$")
36-
var nilValueTypeRegex = regexp.MustCompile("^\\(.*?\\)")
37-
3834
func formatNextListKeyPrefix(prefix string, index int) string {
3935
return fmt.Sprintf("%s[%d]", prefix, index)
4036
}
@@ -81,16 +77,10 @@ func parseNilValueType(key string, description helm.ChartValueDescription, autoD
8177
if len(description.Description) == 0 {
8278
description.Description = autoDescription.Description
8379
}
84-
// Grab whatever's in between the parentheses of the description and treat it as the type
85-
t := nilValueTypeRegex.FindString(description.Description)
86-
87-
if len(t) > 0 {
88-
t = t[1 : len(t)-1]
89-
if len(description.Description) > len(t)+3 {
90-
description.Description = description.Description[len(t)+3:]
91-
} else {
92-
description.Description = ""
93-
}
80+
81+
var t string
82+
if description.ValueType != "" {
83+
t = description.ValueType
9484
} else if autoDescription.ValueType != "" {
9585
// Use whatever the type recognized by autoDescription parser
9686
t = autoDescription.ValueType

pkg/document/values_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -950,10 +950,10 @@ animals:
950950
`)
951951

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

959959
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)
@@ -999,8 +999,8 @@ animals:
999999
`)
10001000

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

0 commit comments

Comments
 (0)