Skip to content

Commit

Permalink
Merge pull request #19 from norwoodj/minor-fixes
Browse files Browse the repository at this point in the history
fix: cleans up some code and minor fix to ignore case
  • Loading branch information
norwoodj authored Aug 13, 2019
2 parents c8635e6 + 33f87b1 commit e08b97e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/norwoodj/helm-docs
rev: v0.7.0
rev: v0.8.0
hooks:
- id: helm-docs
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,14 @@ configMap:

## Pre-commit hook

If you want to automatically generate `README.md` files with a pre-commit hook, make sure you have the `pre-commit` binary installed (instructions here: [https://pre-commit.com/#install](https://pre-commit.com/#install)), and add the following file to your Helm charts repository:
If you want to automatically generate `README.md` files with a pre-commit hook, make sure you
[install the pre-commit binary](https://pre-commit.com/#install), and add a [.pre-commit-config.yaml file](./.pre-commit-config.yaml)
to your project. Then run:

**.pre-commit-config.yaml**
```yaml
- repo: https://github.com/norwoodj/helm-docs
rev: master
hooks:
- id: helm_docs
```bash
pre-commit install
pre-commit install-hooks
```

Future changes to your charts requirements.yaml, values.yaml, or Chart.yaml files will cause an update to documentation when
you commit.
34 changes: 5 additions & 29 deletions pkg/document/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
stringType = "string"
)

var nilValueTypeRegex, _ = regexp.Compile("^\\(.*?\\)")
var nilValueTypeRegex = regexp.MustCompile("^\\(.*?\\)")

func formatNextListKeyPrefix(prefix string, index int) string {
return fmt.Sprintf("%s[%d]", prefix, index)
Expand Down Expand Up @@ -109,24 +109,12 @@ func createRowsFromField(
keysToDescriptions map[string]string,
documentLeafNodes bool,
) ([]valueRow, error) {
valueRows := make([]valueRow, 0)

switch value.(type) {
case map[interface{}]interface{}:
subObjectValuesRows, err := createValueRowsFromObject(nextPrefix, value.(map[interface{}]interface{}), keysToDescriptions, documentLeafNodes)
if err != nil {
return nil, err
}

valueRows = append(valueRows, subObjectValuesRows...)
return createValueRowsFromObject(nextPrefix, value.(map[interface{}]interface{}), keysToDescriptions, documentLeafNodes)

case []interface{}:
subListValuesRows, err := createValueRowsFromList(nextPrefix, value.([]interface{}), keysToDescriptions, documentLeafNodes)
if err != nil {
return nil, err
}

valueRows = append(valueRows, subListValuesRows...)
return createValueRowsFromList(nextPrefix, value.([]interface{}), keysToDescriptions, documentLeafNodes)

default:
description, hasDescription := keysToDescriptions[nextPrefix]
Expand All @@ -135,14 +123,8 @@ func createRowsFromField(
}

leafValueRow, err := createValueRow(nextPrefix, value, description)
if err != nil {
return nil, err
}

valueRows = append(valueRows, leafValueRow)
return []valueRow{leafValueRow}, err
}

return valueRows, nil
}

func createValueRowsFromList(
Expand All @@ -156,7 +138,6 @@ func createValueRowsFromList(
// If we encounter an empty list, it should be documented if no parent object or list had a description or if this
// list has a description
if len(values) == 0 {

if !(documentLeafNodes || hasDescription) {
return []valueRow{}, nil
}
Expand Down Expand Up @@ -221,12 +202,7 @@ func createValueRowsFromObject(
}

documentedRow, err := createValueRow(prefix, jsonableMap{}, description)

if err != nil {
return nil, err
}

return []valueRow{documentedRow}, nil
return []valueRow{documentedRow}, err
}

valueRows := make([]valueRow, 0)
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewIgnoreContext(ignoreFilename string) IgnoreContext {

if err != nil {
log.Warnf("Using empty ignore rules due to error: %s", err)
return IgnoreContext{rules: ignoreRules}
return IgnoreContext{rules: ignore.Empty()}
}

return IgnoreContext{rules: ignoreRules, relativeDir: gitRepositoryRoot}
Expand Down

0 comments on commit e08b97e

Please sign in to comment.