Skip to content

Commit f83a5b5

Browse files
authored
Merge pull request #60 from norwoodj/new-style-comment-parity
feat: Largely expands all features for old comments to new comments, …
2 parents 52f4bc6 + d88cca4 commit f83a5b5

File tree

17 files changed

+234
-123
lines changed

17 files changed

+234
-123
lines changed

README.md

+29-28
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ GO111MODULE=on go get github.com/norwoodj/helm-docs/cmd/helm-docs
5353

5454
## Usage
5555

56-
## Pre-commit hook
56+
### Pre-commit hook
5757

5858
If you want to automatically generate `README.md` files with a pre-commit hook, make sure you
5959
[install the pre-commit binary](https://pre-commit.com/#install), and add a [.pre-commit-config.yaml file](./.pre-commit-config.yaml)
@@ -66,7 +66,7 @@ pre-commit install-hooks
6666

6767
Future changes to your chart's `requirements.yaml`, `values.yaml`, `Chart.yaml`, or `README.md.gotmpl` files will cause an update to documentation when you commit.
6868

69-
## Running the binary directly
69+
### Running the binary directly
7070

7171
To run and generate documentation into READMEs for all helm charts within or recursively contained by a directory:
7272

@@ -79,7 +79,7 @@ helm-docs --dry-run # prints generated documentation to stdout rather than modif
7979
The tool searches recursively through subdirectories of the current directory for `Chart.yaml` files and generates documentation
8080
for every chart that it finds.
8181

82-
## Using docker
82+
### Using docker
8383

8484
You can mount a directory with charts under `/helm-docs` within the container.
8585

@@ -89,7 +89,7 @@ Then run:
8989
docker run --rm --volume "$(pwd):/helm-docs" -u $(id -u) jnorwood/helm-docs:latest
9090
```
9191

92-
# Building from source
92+
### Building from source
9393
Notice that you need to have build chain toolkit for given platform and golang installed.
9494
Next you may need to export some vars to build standalone, non-linked binary for given platform and architecture:
9595

@@ -101,26 +101,35 @@ make test
101101
make
102102
```
103103

104-
## Available Templates
105-
The templates generated by the tool are shown below, and can be included in your `README.md.gotmpl` file like so:
104+
## Ignoring Chart Directories
105+
helm-docs supports a `.helmdocsignore` file, exactly like a `.gitignore` file in which one can specify directories to ignore
106+
when searching for charts. Directories specified need not be charts themselves, so parent directories containing potentially
107+
many charts can be ignored and none of the charts underneath them will be processed. You may also directly reference the
108+
Chart.yaml file for a chart to skip processing for it.
109+
110+
111+
## Markdown Rendering
112+
The helm-docs tool uses go-templates to render output documentation. There are a number of sub-templates that are
113+
referenced in the internal default template and can be used by custom `README.md.gotmpl` templates your repository provides as well.
114+
115+
Templates can be invoked like so:
106116
```
107117
{{ template "template-name" . }}
108118
```
109119

120+
And the complete listing of available templates is below:
121+
110122
| Name | Description |
111123
|------|-------------|
112124
| chart.header | The main heading of the generated markdown file |
113125
| chart.name | The _name_ field from the chart's `Chart.yaml` file |
114126
| chart.deprecationWarning | A deprecation warning which is displayed when the _deprecated_ field from the chart's `Chart.yaml` file is `true` |
115127
| chart.description | A description line containing the _description_ field from the chart's `Chart.yaml` file, or "" if that field is not set |
116128
| chart.version | The _version_ field from the chart's `Chart.yaml` file |
117-
| chart.versionLine | A text line stating the current version of the chart |
118129
| chart.versionBadge | A badge stating the current version of the chart |
119130
| chart.type | The _type_ field from the chart's `Chart.yaml` file |
120-
| chart.typeLine | A text line stating the current type of the chart |
121131
| chart.typeBadge | A badge stating the current type of the chart |
122132
| chart.appVersion | The _appVersion_ field from the chart's `Chart.yaml` file |
123-
| chart.appVersionLine | A text line stating the current appVersion of the chart |
124133
| chart.appVersionBadge | A badge stating the current appVersion of the chart |
125134
| chart.homepage | The _home_ link from the chart's `Chart.yaml` file, or "" if that field is not set |
126135
| chart.homepageLine | A text line stating the current homepage of the chart |
@@ -167,14 +176,7 @@ The tool includes the [sprig templating library](https://github.com/Masterminds/
167176
in the templates you supply.
168177

169178

170-
## Ignoring Chart Directories
171-
helm-docs supports a `.helmdocsignore` file, exactly like a `.gitignore` file in which one can specify directories to ignore
172-
when searching for charts. Directories specified need not be charts themselves, so parent directories containing potentially
173-
many charts can be ignored and none of the charts underneath them will be processed. You may also directly reference the
174-
Chart.yaml file for a chart to skip processing for it.
175-
176-
177-
## values.yaml metadata
179+
### values.yaml metadata
178180
This tool can parse descriptions and defaults of values from `values.yaml` files. The defaults are pulled directly from
179181
the yaml in the file.
180182

@@ -199,21 +201,19 @@ controller:
199201
# -- Whether to expose the ingress controller to the public world
200202
enabled: false
201203
202-
# -- Number of nginx-ingress pods to load balance between. Do not set this below 2.
204+
# -- Number of nginx-ingress pods to load balance between.
205+
# Do not set this below 2.
203206
replicas: 2
204207
```
205208

206-
There are a number of limitations to this comment format, the foremost being that they can only comprise a single line and while
207-
the old-style comment for a field could appear anywhere in the file, the new comment must appear **on the line immediately preceding the field being documented.**
208-
209-
Additionally, there are a number of methods for encoding more data in the old comment format, documented later in this guide. These
210-
extensions are largely not supported with the new _auto-detection_ format.
209+
New-style comments are much the same as the old-style comments, except that while old comments for a field could appear
210+
anywhere in the file, new-style comments must appear **on the line(s) immediately preceding the field being documented.**
211211

212212
I invite you to check out the [example-charts](./example-charts) to see how this is done in practice. The `but-auto-comments`
213213
examples in particular document the new comment format.
214214

215-
Note that comments of the old form can continue on the next line. In that case leave out the double dash, and the lines
216-
will simply be appended with a space in-between.
215+
Note that comments can continue on the next line. In that case leave out the double dash, and the lines will simply be
216+
appended with a space in-between, as in the `controller.replicas` field in the example above
217217

218218
The following rules are used to determine which values will be added to the values table in the README:
219219

@@ -283,13 +283,14 @@ inside the chart, you can change the contents of the column like so:
283283

284284
```yaml
285285
service:
286-
# service.annotations -- Add annotations to the service
286+
# -- Add annotations to the service, this is going to be a long comment across multiple lines
287+
# but that's fine, these will be concatenated and the @default will be rendered as the default for this field
287288
# @default -- the chart will add some internal annotations automatically
288289
annotations: []
289290
```
290291

291-
The order is important. The name must be spelled just like the column heading. The first comment must be the
292-
one specifying the key. The "@default" comment must follow. This is only possible with the old comment format
292+
The order is important. The first comment line(s) must be the one specifying the key or using the auto-detection feature and
293+
the description for the field. The `@default` comment must follow.
293294

294295
See [here](./example-charts/custom-template/values.yaml) for an example.
295296

example-charts/custom-template/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Basically the same as the nginx-ingress chart, but using a custom template to include some other content
44

5-
Current chart version is `0.2.0`
5+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)
66

77
## Additional Information
88

example-charts/custom-template/README.md.gotmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{ template "chart.header" . }}
22
{{ template "chart.description" . }}
33

4-
{{ template "chart.versionLine" . }}
4+
{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}
55

66
## Additional Information
77

example-charts/custom-template/values.yaml

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@ controller:
44
repository: nginx-ingress-controller
55
tag: "18.0831"
66

7-
# controller.persistentVolumeClaims -- List of persistent volume claims to create.
7+
# -- List of persistent volume claims to create.
88
# For very long comments, break them into multiple lines.
99
# @default -- the chart will construct this list internally unless specified
1010
persistentVolumeClaims: []
1111

1212
extraVolumes:
1313
- name: config-volume
1414
configMap:
15-
# controller.extraVolumes[0].configMap.name -- Uses the name of the configmap created by this chart
15+
# -- Uses the name of the configmap created by this chart
1616
name: nginx-ingress-config
1717

18-
# controller.ingressClass -- Name of the ingress class to route through this controller
18+
# -- Name of the ingress class to route through this controller
1919
ingressClass: nginx
2020

21-
# controller.podLabels -- The labels to be applied to instances of the controller pod
21+
# -- The labels to be applied to instances of the controller pod
2222
podLabels: {}
2323

2424
publishService:
25-
# controller.publishService.enabled -- Whether to expose the ingress controller to the public world
25+
# -- Whether to expose the ingress controller to the public world
2626
enabled: false
2727

28-
# controller.replicas -- (int) Number of nginx-ingress pods to load balance between
28+
# -- (int) Number of nginx-ingress pods to load balance between
2929
replicas:
3030

3131
service:
3232
annotations:
33-
# controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" -- Hostname to be assigned to the ELB for the service
33+
# -- Hostname to be assigned to the ELB for the service
3434
external-dns.alpha.kubernetes.io/hostname: stupidchess.jmn23.com
3535

3636
type: LoadBalancer

example-charts/full-template/README.md

-12
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ A chart for showing every README-element
1616

1717
1.0.0
1818

19-
## `chart.versionLine`
20-
21-
Current chart version is `1.0.0`
22-
2319
## `chart.versionBadge`
2420

2521
![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square)
@@ -28,10 +24,6 @@ Current chart version is `1.0.0`
2824

2925
application
3026

31-
## `chart.typeLine`
32-
33-
Current chart type is `application`
34-
3527
## `chart.typeBadge`
3628

3729
![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
@@ -40,10 +32,6 @@ Current chart type is `application`
4032

4133
13.0.0
4234

43-
## `chart.appVersionLine`
44-
45-
Current chart appVersion is `13.0.0`
46-
4735
## `chart.appVersionBadge`
4836

4937
![AppVersion: 13.0.0](https://img.shields.io/badge/AppVersion-13.0.0-informational?style=flat-square)

example-charts/full-template/README.md.gotmpl

-11
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222

2323
{{ template "chart.version" . }}
2424

25-
## `chart.versionLine`
26-
27-
{{ template "chart.versionLine" . }}
28-
2925
## `chart.versionBadge`
3026

3127
{{ template "chart.versionBadge" . }}
@@ -34,9 +30,6 @@
3430

3531
{{ template "chart.type" . }}
3632

37-
## `chart.typeLine`
38-
39-
{{ template "chart.typeLine" . }}
4033

4134
## `chart.typeBadge`
4235

@@ -46,10 +39,6 @@
4639

4740
{{ template "chart.appVersion" . }}
4841

49-
## `chart.appVersionLine`
50-
51-
{{ template "chart.appVersionLine" . }}
52-
5342
## `chart.appVersionBadge`
5443

5544
{{ template "chart.appVersionBadge" . }}

example-charts/most-empty/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# most-empty
22

3-
Current chart version is `0.2.0`
3+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)
44

55
This is a good example of all the fields that don't appear when they aren't set in chart metadata. `description`,
66
`requirements`, and `values` are all empty and don't appear here.

example-charts/most-empty/README.md.gotmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{ template "chart.header" . }}
22
{{ template "chart.description" . }}
33

4-
{{ template "chart.versionLine" . }}
4+
{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}
55

66
This is a good example of all the fields that don't appear when they aren't set in chart metadata. `description`,
77
`requirements`, and `values` are all empty and don't appear here.

example-charts/nginx-ingress-but-auto-comments/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co
3434
| controller.livenessProbe.httpGet.path | string | `"/healthz"` | This is the liveness check endpoint |
3535
| controller.name | string | `"controller"` | |
3636
| controller.persistentVolumeClaims | list | `[]` | List of persistent volume claims to create |
37-
| controller.podLabels | object | `{}` | The labels to be applied to instances of the controller pod |
37+
| controller.podLabels | object | A number of chart-specific labels | The labels to be applied to instances of the controller pod. By default, a number of labels will automatically be applied |
3838
| controller.publishService.enabled | bool | `false` | Whether to expose the ingress controller to the public world |
39-
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between |
39+
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between. Do not set this below 2 |
4040
| controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service |
4141
| controller.service.type | string | `"LoadBalancer"` | |

example-charts/nginx-ingress-but-auto-comments/values.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ controller:
2323
# -- Name of the ingress class to route through this controller
2424
ingressClass: nginx
2525

26-
# -- The labels to be applied to instances of the controller pod
26+
# -- The labels to be applied to instances of the controller pod.
27+
# By default, a number of labels will automatically be applied
28+
# @default -- A number of chart-specific labels
2729
podLabels: {}
2830

2931
publishService:
3032
# -- Whether to expose the ingress controller to the public world
3133
enabled: false
3234

33-
# -- (int) Number of nginx-ingress pods to load balance between
35+
# -- (int) Number of nginx-ingress pods to load balance between.
36+
# Do not set this below 2
3437
replicas:
3538

3639
service:

example-charts/special-characters-but-auto-comments/values.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ htmlSnippets:
1818
two: ""
1919

2020
# -- Another description
21-
three: "<html><head></head></html>"
21+
# @default -- `"<html><head></head></html>"`
22+
three: ""

pkg/document/model.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
type valueRow struct {
1212
Key string
1313
Type string
14+
AutoDefault string
1415
Default string
1516
AutoDescription string
1617
Description string

pkg/document/template.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ func getDeprecatedTemplate() string {
6161
func getVersionTemplates() string {
6262
versionBuilder := strings.Builder{}
6363
versionBuilder.WriteString(`{{ define "chart.version" }}{{ .Version }}{{ end }}\n`)
64-
versionBuilder.WriteString(`{{ define "chart.versionLine" }}`)
65-
versionBuilder.WriteString("{{ if .Version }}Current chart version is `{{ .Version }}`{{ end }}")
66-
versionBuilder.WriteString("{{ end }}")
6764
versionBuilder.WriteString(`{{ define "chart.versionBadge" }}`)
6865
versionBuilder.WriteString("![Version: {{ .Version }}](https://img.shields.io/badge/Version-{{ .Version }}-informational?style=flat-square) ")
6966
versionBuilder.WriteString("{{ end }}")
@@ -74,9 +71,6 @@ func getVersionTemplates() string {
7471
func getTypeTemplate() string {
7572
typeBuilder := strings.Builder{}
7673
typeBuilder.WriteString(`{{ define "chart.type" }}{{ .Type }}{{ end }}\n`)
77-
typeBuilder.WriteString(`{{ define "chart.typeLine" }}`)
78-
typeBuilder.WriteString("{{ if .Type }}Current chart type is `{{ .Type }}`{{ end }}")
79-
typeBuilder.WriteString("{{ end }}")
8074
typeBuilder.WriteString(`{{ define "chart.typeBadge" }}`)
8175
typeBuilder.WriteString("{{ if .Type }}![Type: {{ .Type }}](https://img.shields.io/badge/Type-{{ .Type }}-informational?style=flat-square) {{ end }}")
8276
typeBuilder.WriteString("{{ end }}")
@@ -87,9 +81,6 @@ func getTypeTemplate() string {
8781
func getAppVersionTemplate() string {
8882
appVersionBuilder := strings.Builder{}
8983
appVersionBuilder.WriteString(`{{ define "chart.appVersion" }}{{ .AppVersion }}{{ end }}\n`)
90-
appVersionBuilder.WriteString(`{{ define "chart.appVersionLine" }}`)
91-
appVersionBuilder.WriteString("{{ if .AppVersion }}Current chart appVersion is `{{ .AppVersion }}`{{ end }}")
92-
appVersionBuilder.WriteString("{{ end }}")
9384
appVersionBuilder.WriteString(`{{ define "chart.appVersionBadge" }}`)
9485
appVersionBuilder.WriteString("{{ if .AppVersion }}![AppVersion: {{ .AppVersion }}](https://img.shields.io/badge/AppVersion-{{ .AppVersion }}-informational?style=flat-square) {{ end }}")
9586
appVersionBuilder.WriteString("{{ end }}")
@@ -202,7 +193,7 @@ func getValuesTableTemplates() string {
202193
valuesSectionBuilder.WriteString("| Key | Type | Default | Description |\n")
203194
valuesSectionBuilder.WriteString("|-----|------|---------|-------------|\n")
204195
valuesSectionBuilder.WriteString(" {{- range .Values }}")
205-
valuesSectionBuilder.WriteString("\n| {{ .Key }} | {{ .Type }} | {{ .Default }} | {{ if .Description }}{{ .Description }}{{ else }}{{ .AutoDescription }}{{ end }} |")
196+
valuesSectionBuilder.WriteString("\n| {{ .Key }} | {{ .Type }} | {{ if .Default }}{{ .Default }}{{ else }}{{ .AutoDefault }}{{ end }} | {{ if .Description }}{{ .Description }}{{ else }}{{ .AutoDescription }}{{ end }} |")
206197
valuesSectionBuilder.WriteString(" {{- end }}")
207198
valuesSectionBuilder.WriteString("{{ end }}")
208199

0 commit comments

Comments
 (0)