Skip to content

Commit

Permalink
adding ignore-non-descriptions flag
Browse files Browse the repository at this point in the history
  • Loading branch information
David Wertenteil committed May 23, 2022
1 parent 72e085f commit a5a2be9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/helm-docs/command_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func newHelmDocsCommand(run func(cmd *cobra.Command, args []string)) (*cobra.Com
logLevelUsage := fmt.Sprintf("Level of logs that should printed, one of (%s)", strings.Join(possibleLogLevels(), ", "))
command.PersistentFlags().StringP("chart-search-root", "c", ".", "directory to search recursively within for charts")
command.PersistentFlags().BoolP("dry-run", "d", false, "don't actually render any markdown files just print to stdout passed")
command.PersistentFlags().Bool("ignore-non-descriptions", false, "ignore values without a comment, this values will not be included in the README")
command.PersistentFlags().StringP("ignore-file", "i", ".helmdocsignore", "The filename to use as an ignore file to exclude chart directories")
command.PersistentFlags().StringP("log-level", "l", "info", logLevelUsage)
command.PersistentFlags().StringP("output-file", "o", "README.md", "markdown file path relative to each chart directory to which rendered documentation will be written")
Expand Down
15 changes: 15 additions & 0 deletions pkg/document/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func getChartTemplateData(info helm.ChartDocumentationInfo, helmDocsVersion stri
return chartTemplateData{}, err
}

if viper.GetBool("ignore-non-descriptions") {
valuesTableRows = removeRowsWithoutDescription(valuesTableRows)
}

if len(dependencyValues) > 0 {
seenGlobalKeys := make(map[string]bool)
for i, row := range valuesTableRows {
Expand Down Expand Up @@ -137,3 +141,14 @@ func getChartTemplateData(info helm.ChartDocumentationInfo, helmDocsVersion stri
Values: valuesTableRows,
}, nil
}

func removeRowsWithoutDescription(valuesTableRows []valueRow) []valueRow {

var valuesTableRowsWithoutDescription []valueRow
for i := range valuesTableRows {
if valuesTableRows[i].AutoDescription != "" || valuesTableRows[i].Description != "" {
valuesTableRowsWithoutDescription = append(valuesTableRowsWithoutDescription, valuesTableRows[i])
}
}
return valuesTableRowsWithoutDescription
}
2 changes: 1 addition & 1 deletion pkg/document/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func getDescriptionFromNode(node *yaml.Node) helm.ChartValueDescription {
return helm.ChartValueDescription{}
}

if !strings.Contains(node.HeadComment, "# --") {
if !strings.Contains(node.HeadComment, helm.PrefixComment) {
return helm.ChartValueDescription{}
}
commentLines := strings.Split(node.HeadComment, "\n")
Expand Down
6 changes: 5 additions & 1 deletion pkg/helm/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"strings"
)

const (
PrefixComment = "# --"
)

func ParseComment(commentLines []string) (string, ChartValueDescription) {
var valueKey string
var c ChartValueDescription
Expand All @@ -13,7 +17,7 @@ func ParseComment(commentLines []string) (string, ChartValueDescription) {
// the last "group" of comment lines starting with '# --'.
lastIndex := 0
for i, v := range commentLines {
if strings.HasPrefix(v, "# --") {
if strings.HasPrefix(v, PrefixComment) {
lastIndex = i
}
}
Expand Down

0 comments on commit a5a2be9

Please sign in to comment.