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

adding ignore-non-descriptions flag #151

Merged
merged 1 commit into from
Jun 29, 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
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