Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: types on nil values #140

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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