Skip to content

Commit 27a6b89

Browse files
committed
initial version
1 parent 97edd6d commit 27a6b89

18 files changed

+1122
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,19 @@
88
# Test binary, build with `go test -c`
99
*.test
1010

11+
### IntelliJ IDEA ###
12+
.idea
13+
*.iws
14+
*.iml
15+
*.ipr
16+
17+
### Visual Studio Code
18+
.vscode
19+
20+
### Binary
21+
docs
22+
dist
23+
helm-doc
24+
1125
# Output of the go coverage tool, specifically when used with LiteIDE
1226
*.out

.goreleaser.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
builds:
5+
- env:
6+
- CGO_ENABLED=0
7+
ldflags:
8+
- -s -w -X github.com/random-dwi/helm-doc/cmd.version={{.Version}} -X github.com/random-dwi/helm-doc/cmd.gitCommit={{.ShortCommit}} -X github.com/random-dwi/helm-doc/cmd.buildTime={{.Date}}
9+
goos:
10+
- darwin
11+
- linux
12+
13+
archive:
14+
replacements:
15+
darwin: Darwin
16+
linux: Linux
17+
386: i386
18+
amd64: x86_64
19+
files:
20+
- LICENSE.md
21+
22+
checksum:
23+
name_template: 'checksums.txt'
24+
25+
release:
26+
disable: false

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: go
2+
go:
3+
- 1.11.x
4+
env:
5+
global:
6+
- GO111MODULE=on
7+
# travis encrypt GITHUB_TOKEN=xyz --add env.global --com
8+
- secure: cUKs6l3QLBMgSUiUwjjS/K37wUXSGxZPy07bU8D9cuDFsoelTNsqZAAKgXULRxU+zG6Li6hS83FlHuhd2UgJbyk0mMYQUGkc58tCtrEuKtKMoQnkcdHdBkgK5y8RhKHo+W4Kv07jl+6tcZYjspDcL1Qq0RG8u+PhKc/LvGnSPmF9qlpnM+xIrH/TDUS4eD+o0tqopwVAd13S9wlLxVKtiO18N/9KT+FMa7+mWndBJsUxoF0YXPx94fpSfnSoErZe3tcLSy/dlmyZ6UDjhe/98pJoIk4smQP/JxMNu8Tj2SGer1d3vK3H5Lbgm3D7SPawj4UaLkoheNS9EmwQku8nA/H/CN4U+pbnBXamr7s7DnyqUkcddIDEmT32F2M1pxhoRsRUGkhHVAMYnY9YOwXA16PFWrsx9npOPt+b7QkfaR3QYv3XlrIEGjFKdEnSSNZRD1beBxTuwsBD0LK+i3qQ/sXlHQuD13KQO2+D9LbNWSlONMvwBa6pgMurXovWc/AuGb+lCC6UX0O4+Ngoq/tOXE5wyEjmMquFYgMzyu0BAFV+Nf3oeyu98OKPtRW1KrVs7yT6tshy6gp/+82CddX1yKxKi2m5QQmSiMi9iluGbYN6f3P1gxCEFbTaOwobjEEZrdFnFIjeySWptAKgqfejWGl9M9dmKIRQMWrNBPHsddE=
9+
deploy:
10+
- provider: script
11+
skip_cleanup: true
12+
script: curl -sL https://git.io/goreleaser | bash
13+
on:
14+
branch: master
15+
condition: "$TRAVIS_OS_NAME = linux"
16+
tags: true

LICENSE renamed to LICENSE.md

File renamed without changes.

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
BUILD_TS := $(shell date -Iseconds --utc)
2+
COMMIT_SHA := $(shell git rev-parse HEAD)
3+
VERSION := $(shell git describe --abbrev=0 --tags)
4+
5+
export CGO_ENABLED=0
6+
export GOOS=linux
7+
export GO111MODULE=on
8+
9+
project=github.com/random-dwi/helm-doc
10+
ld_flags := "-X $(project)/cmd.version=$(VERSION) -X $(project)/cmd.gitCommit=$(COMMIT_SHA) -X $(project)/cmd.buildTime=$(BUILD_TS)"
11+
12+
.DEFAULT_GOAL := all
13+
.PHONY: all
14+
all: vet test build
15+
16+
.PHONY: vet
17+
vet:
18+
go vet ./...
19+
20+
.PHONY: test
21+
test:
22+
go test ./...
23+
24+
.PHONY: build
25+
build:
26+
go build -ldflags $(ld_flags) -o helm-doc
27+
28+
.PHONY: clean
29+
clean:
30+
rm -f helm-doc
31+
go clean -testcache
32+
33+
# usage make version=0.0.4 release
34+
#
35+
# manually executing goreleaser:
36+
# export GITHUB_TOKEN=xyz
37+
# goreleaser --rm-dist
38+
#
39+
.PHONY: release
40+
release:
41+
git tag -a $(version) -m "release $(version)"
42+
git push origin
43+
git push origin $(version)

cmd/cmd.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"github.com/random-dwi/helm-doc/generator"
7+
"github.com/random-dwi/helm-doc/helm"
8+
"github.com/random-dwi/helm-doc/output"
9+
"github.com/random-dwi/helm-doc/writer"
10+
"github.com/spf13/cobra"
11+
"k8s.io/helm/pkg/chartutil"
12+
"log"
13+
"os"
14+
)
15+
16+
var version string
17+
var buildTime string
18+
var gitCommit string
19+
20+
var rootCmd = &cobra.Command{
21+
Use: "doc [flags] CHART",
22+
Short: fmt.Sprintf("generate doc for a helm chart"),
23+
Long: fmt.Sprintf("helm plugin to generate documentation for helm charts.\nversion: %s buildTime: %s gitCommit: %s", version, buildTime, gitCommit),
24+
RunE: run,
25+
}
26+
27+
var flags generator.CommandFlags
28+
29+
func HelmDocCommand(streams output.IOStreams) *cobra.Command {
30+
rootCmd.SetOutput(streams.Out)
31+
return rootCmd
32+
}
33+
34+
func defaultKeyring() string {
35+
return os.ExpandEnv("$HOME/.gnupg/pubring.gpg")
36+
}
37+
38+
func init() {
39+
40+
f := rootCmd.Flags()
41+
f.BoolVarP(&flags.VerifyExamples, "verify-examples", "", true, "verify presence of examples for configs without default value")
42+
f.BoolVarP(&flags.VerifyValues, "verify-values", "", true, "verify all default values are documented")
43+
f.BoolVarP(&flags.VerifyDependencies, "verify-dependencies", "", false, "verify dependencies are documented")
44+
f.StringVar(&flags.Version, "version", "", "Specify the exact chart version to use. If this is not specified, the latest version is used")
45+
f.StringVar(&flags.RepoURL, "repo", "", "Chart repository url where to locate the requested chart")
46+
f.StringVar(&flags.Username, "username", "", "Chart repository username where to locate the requested chart")
47+
f.StringVar(&flags.Password, "password", "", "Chart repository password where to locate the requested chart")
48+
f.StringVar(&flags.Keyring, "keyring", defaultKeyring(), "Location of public keys used for verification")
49+
f.StringVar(&flags.CertFile, "cert-file", "", "Identify HTTPS client using this SSL certificate file")
50+
f.StringVar(&flags.KeyFile, "key-file", "", "Identify HTTPS client using this SSL key file")
51+
f.StringVar(&flags.CaFile, "ca-file", "", "Verify certificates of HTTPS-enabled servers using this CA bundle")
52+
f.BoolVar(&flags.Verify, "verify", false, "Verify the package before using it")
53+
f.BoolVar(&flags.Devel, "devel", false, "Use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.")
54+
55+
if os.Getenv("HELM_DEBUG") == "1" {
56+
flags.Verbose = true
57+
}
58+
}
59+
60+
func run(cmd *cobra.Command, args []string) error {
61+
if len(args) < 1 {
62+
return errors.New("chart is required")
63+
}
64+
65+
if flags.Verbose {
66+
output.DebugLogger = log.New(os.Stderr, "[doc] ", log.LstdFlags)
67+
}
68+
69+
output.Debugf("helm home: %s", os.Getenv("HELM_HOME"))
70+
71+
output.Debugf("Original chart version: %q", flags.Version)
72+
if flags.Version == "" && flags.Devel {
73+
output.Debugf("setting version to >0.0.0-0")
74+
flags.Version = ">0.0.0-0"
75+
}
76+
77+
cp, err := helm.LocateChartPath(flags.RepoURL, flags.Username, flags.Password, args[0], flags.Version, flags.Verify, flags.Keyring,
78+
flags.CertFile, flags.KeyFile, flags.CaFile)
79+
if err != nil {
80+
return err
81+
}
82+
var chartPath = cp
83+
84+
output.Debugf("ChartPath is: %s", chartPath)
85+
86+
c, err := chartutil.Load(chartPath)
87+
if err != nil {
88+
return err
89+
}
90+
91+
var gen writer.DocumentationWriter = writer.NewMarkdownWriter(os.Stdout)
92+
93+
var dependencyNames []string
94+
95+
for _, dependency := range c.Dependencies {
96+
dependencyNames = append(dependencyNames, dependency.Metadata.Name)
97+
}
98+
99+
output.Debugf("generating docs for %s:%s", c.Metadata.Name, c.Metadata.Version)
100+
docs, err := generator.GenerateDocs(c, dependencyNames, flags)
101+
102+
gen.WriteMetaData(c.Metadata, 1)
103+
gen.WriteDocs(docs)
104+
105+
if len(c.Dependencies) > 0 {
106+
gen.WriteChapter("Dependencies", 2)
107+
}
108+
109+
for _, dependency := range c.Dependencies {
110+
output.Debugf("generating docs for %s:%s", dependency.Metadata.Name, dependency.Metadata.Version)
111+
docs, err := generator.GenerateDocs(dependency, nil, flags)
112+
113+
if err != nil {
114+
if flags.VerifyDependencies {
115+
output.Failf("%v", err)
116+
} else {
117+
output.Warnf("%v", err)
118+
}
119+
} else {
120+
gen.WriteMetaData(dependency.Metadata, 3)
121+
gen.WriteDocs(docs)
122+
}
123+
}
124+
125+
return nil
126+
}

0 commit comments

Comments
 (0)