feat(helm): add command to generate documentation

This adds a hidden 'helm doc' command that generates documentation out
of the Helm help text.

Currently it can create:

- man pages for HELM(1)
- Markdown documentation
- bash autocompletions

Those are the three built-ins for Cobra.

The command is hidden so that it doesn't show up to the regular user,
since this is really a specialized task. It has the advantage of making
it trivially easy to install man pages and bash completion at installation time.
reviewable/pr1484/r1
Matt Butcher 9 years ago
parent 846011b02a
commit 28c29c60a4
No known key found for this signature in database
GPG Key ID: DCD5F5E5EF32C345

@ -0,0 +1,80 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"fmt"
"io"
"path/filepath"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
const docsDesc = `
Generate documentation files for Helm.
This command can generate documentation for Helm in the following formats:
- Markdown
- Man pages
It can also generate bash autocompletions.
$ helm docs markdown -dir mydocs/
`
type docsCmd struct {
out io.Writer
dest string
docTypeString string
topCmd *cobra.Command
}
func newDocsCmd(out io.Writer, topCmd *cobra.Command) *cobra.Command {
dc := &docsCmd{out: out, topCmd: topCmd}
cmd := &cobra.Command{
Use: "docs",
Short: "Generate documentation as markdown or man pages",
Long: docsDesc,
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
dc.run()
return nil
},
}
f := cmd.Flags()
f.StringVar(&dc.dest, "dir", "./", "directory to which documentation is written")
f.StringVar(&dc.docTypeString, "type", "markdown", "the type of documentation to generate (markdown, man, bash)")
return cmd
}
func (d *docsCmd) run() error {
switch d.docTypeString {
case "markdown", "mdown", "md":
return doc.GenMarkdownTree(d.topCmd, d.dest)
case "man":
manHdr := &doc.GenManHeader{Title: "HELM", Section: "1"}
return doc.GenManTree(d.topCmd, manHdr, d.dest)
case "bash":
return d.topCmd.GenBashCompletionFile(filepath.Join(d.dest, "completions.bash"))
default:
return fmt.Errorf("unknown doc type %q. Try 'markdown' or 'man'", d.docTypeString)
}
}

@ -115,6 +115,7 @@ func newRootCmd(out io.Writer) *cobra.Command {
newUpgradeCmd(nil, out), newUpgradeCmd(nil, out),
newVerifyCmd(out), newVerifyCmd(out),
newVersionCmd(nil, out), newVersionCmd(nil, out),
newDocsCmd(out, cmd),
// Deprecated // Deprecated
rup, rup,
) )

124
glide.lock generated

@ -1,8 +1,11 @@
hash: e04a956fc7be01bd1a2450cdc0000ed25394da383f0c7a7e057a9377bd832c1e hash: e04a956fc7be01bd1a2450cdc0000ed25394da383f0c7a7e057a9377bd832c1e
updated: 2016-10-13T12:28:13.380298639-07:00 updated: 2016-10-31T17:29:36.362855971-06:00
imports: imports:
- name: bitbucket.org/ww/goautoneg - name: cloud.google.com/go
version: 75cd24fc2f2c2a2088577d12123ddee5f54e0675 version: 3b1ae45394a234c385be014e9a488f2bb6eef821
subpackages:
- compute/metadata
- internal
- name: github.com/aokoli/goutils - name: github.com/aokoli/goutils
version: 9c37978a95bd5c709a15883b6242714ea6709e64 version: 9c37978a95bd5c709a15883b6242714ea6709e64
- name: github.com/asaskevich/govalidator - name: github.com/asaskevich/govalidator
@ -11,67 +14,8 @@ imports:
version: 70b2c90b260171e829f1ebd7c17f600c11858dbe version: 70b2c90b260171e829f1ebd7c17f600c11858dbe
subpackages: subpackages:
- winterm - winterm
- name: github.com/beorn7/perks
version: 3ac7bf7a47d159a033b107610db8a1b6575507a4
subpackages:
- quantile
- name: github.com/blang/semver - name: github.com/blang/semver
version: 31b736133b98f26d5e078ec9eb591666edfd091f version: 31b736133b98f26d5e078ec9eb591666edfd091f
- name: github.com/coreos/etcd
version: 9efa00d1030d4bf62eb8e5ec130023aeb1b8e2d0
subpackages:
- alarm
- auth
- auth/authpb
- client
- clientv3
- compactor
- discovery
- error
- etcdserver
- etcdserver/api
- etcdserver/api/v2http
- etcdserver/api/v2http/httptypes
- etcdserver/api/v3rpc
- etcdserver/api/v3rpc/rpctypes
- etcdserver/auth
- etcdserver/etcdserverpb
- etcdserver/membership
- etcdserver/stats
- integration
- lease
- lease/leasehttp
- lease/leasepb
- mvcc
- mvcc/backend
- mvcc/mvccpb
- pkg/adt
- pkg/contention
- pkg/crc
- pkg/fileutil
- pkg/httputil
- pkg/idutil
- pkg/ioutil
- pkg/logutil
- pkg/netutil
- pkg/pathutil
- pkg/pbutil
- pkg/runtime
- pkg/schedule
- pkg/testutil
- pkg/tlsutil
- pkg/transport
- pkg/types
- pkg/wait
- raft
- raft/raftpb
- rafthttp
- snap
- snap/snappb
- store
- version
- wal
- wal/walpb
- name: github.com/coreos/go-oidc - name: github.com/coreos/go-oidc
version: 5cf2aa52da8c574d3aa4458f471ad6ae2240fe6b version: 5cf2aa52da8c574d3aa4458f471ad6ae2240fe6b
subpackages: subpackages:
@ -97,6 +41,10 @@ imports:
- health - health
- httputil - httputil
- timeutil - timeutil
- name: github.com/cpuguy83/go-md2man
version: a65d4d2de4d5f7c74868dfa9b202a3c8be315aaa
subpackages:
- md2man
- name: github.com/davecgh/go-spew - name: github.com/davecgh/go-spew
version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d
subpackages: subpackages:
@ -192,12 +140,11 @@ imports:
- name: github.com/golang/protobuf - name: github.com/golang/protobuf
version: df1d3ca07d2d07bba352d5b73c4313b4e2a6203e version: df1d3ca07d2d07bba352d5b73c4313b4e2a6203e
subpackages: subpackages:
- jsonpb
- proto - proto
- ptypes/any - ptypes/any
- ptypes/timestamp - ptypes/timestamp
- name: github.com/google/cadvisor - name: github.com/google/cadvisor
version: 0cdf4912793fac9990de3790c273342ec31817fb version: a726d13de8cb32860e73d72a78dc8e0124267709
subpackages: subpackages:
- api - api
- cache/memory - cache/memory
@ -247,12 +194,6 @@ imports:
subpackages: subpackages:
- util/strutil - util/strutil
- util/wordwrap - util/wordwrap
- name: github.com/grpc-ecosystem/grpc-gateway
version: f52d055dc48aec25854ed7d31862f78913cf17d1
subpackages:
- runtime
- runtime/internal
- utilities
- name: github.com/imdario/mergo - name: github.com/imdario/mergo
version: 6633656539c1639d9d78127b7d47c622b5d7b6dc version: 6633656539c1639d9d78127b7d47c622b5d7b6dc
- name: github.com/inconshreveable/mousetrap - name: github.com/inconshreveable/mousetrap
@ -267,33 +208,20 @@ imports:
version: 8f797f5b23118d8fe846c4296b0ad55044201b14 version: 8f797f5b23118d8fe846c4296b0ad55044201b14
- name: github.com/mattn/go-runewidth - name: github.com/mattn/go-runewidth
version: d6bea18f789704b5f83375793155289da36a3c7f version: d6bea18f789704b5f83375793155289da36a3c7f
- name: github.com/matttproud/golang_protobuf_extensions
version: fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a
subpackages:
- pbutil
- name: github.com/pborman/uuid - name: github.com/pborman/uuid
version: ca53cad383cad2479bbba7f7a1a05797ec1386e4 version: ca53cad383cad2479bbba7f7a1a05797ec1386e4
- name: github.com/prometheus/client_golang - name: github.com/russross/blackfriday
version: e51041b3fa41cece0dca035740ba6411905be473 version: 300106c228d52c8941d4b3de6054a6062a86dda3
subpackages:
- prometheus
- name: github.com/prometheus/client_model
version: fa8ad6fec33561be4280a8f0514318c79d7f6cb6
subpackages:
- go
- name: github.com/prometheus/common
version: ffe929a3f4c4faeaa10f2b9535c2b1be3ad15650
subpackages:
- expfmt
- model
- name: github.com/prometheus/procfs
version: 454a56f35412459b5e684fd5ec0f9211b94f002a
- name: github.com/satori/go.uuid - name: github.com/satori/go.uuid
version: 879c5887cd475cd7864858769793b2ceb0d44feb version: 879c5887cd475cd7864858769793b2ceb0d44feb
- name: github.com/shurcooL/sanitized_anchor_name
version: 10ef21a441db47d8b13ebcc5fd2310f636973c77
- name: github.com/Sirupsen/logrus - name: github.com/Sirupsen/logrus
version: 51fe59aca108dc5680109e7b2051cbdcfa5a253c version: 51fe59aca108dc5680109e7b2051cbdcfa5a253c
- name: github.com/spf13/cobra - name: github.com/spf13/cobra
version: 6a8bd97bdb1fc0d08a83459940498ea49d3e8c93 version: 6a8bd97bdb1fc0d08a83459940498ea49d3e8c93
subpackages:
- doc
- name: github.com/spf13/pflag - name: github.com/spf13/pflag
version: 367864438f1b1a3c7db4da06a2f55b144e6784e0 version: 367864438f1b1a3c7db4da06a2f55b144e6784e0
- name: github.com/technosophos/moniker - name: github.com/technosophos/moniker
@ -314,6 +242,7 @@ imports:
- openpgp/errors - openpgp/errors
- openpgp/packet - openpgp/packet
- openpgp/s2k - openpgp/s2k
- ssh/terminal
- name: golang.org/x/net - name: golang.org/x/net
version: fb93926129b8ec0056f2f458b1f519654814edf0 version: fb93926129b8ec0056f2f458b1f519654814edf0
subpackages: subpackages:
@ -325,14 +254,14 @@ imports:
- trace - trace
- websocket - websocket
- name: golang.org/x/oauth2 - name: golang.org/x/oauth2
version: b5adcc2dcdf009d0391547edc6ecbaff889f5bb9 version: 3c3a985cb79f52a3190fbc056984415ca6763d01
subpackages: subpackages:
- google - google
- internal - internal
- jws - jws
- jwt - jwt
- name: google.golang.org/appengine - name: google.golang.org/appengine
version: 12d5545dc1cfa6047a286d5e853841b6471f4c19 version: 4f7eeb5305a4ba1966344836ba4af9996b7b4e05
subpackages: subpackages:
- internal - internal
- internal/app_identity - internal/app_identity
@ -347,9 +276,6 @@ imports:
version: eb47ba841d53d93506cfbfbc03927daf9cc48f88 version: eb47ba841d53d93506cfbfbc03927daf9cc48f88
repo: https://code.googlesource.com/gocloud repo: https://code.googlesource.com/gocloud
vcs: git vcs: git
subpackages:
- compute/metadata
- internal
- name: google.golang.org/grpc - name: google.golang.org/grpc
version: 0032a855ba5c8a3c8e0d71c2deef354b70af1584 version: 0032a855ba5c8a3c8e0d71c2deef354b70af1584
subpackages: subpackages:
@ -434,7 +360,7 @@ imports:
- 1.4/tools/metrics - 1.4/tools/metrics
- 1.4/transport - 1.4/transport
- name: k8s.io/kubernetes - name: k8s.io/kubernetes
version: fc3dab7de68c15de3421896dd051c2f127fb64ab version: 39df7e7ef8b5087b34ff7351f1b7fc1bcc128716
subpackages: subpackages:
- federation/apis/federation - federation/apis/federation
- federation/apis/federation/install - federation/apis/federation/install
@ -547,7 +473,6 @@ imports:
- pkg/kubelet/types - pkg/kubelet/types
- pkg/labels - pkg/labels
- pkg/master/ports - pkg/master/ports
- pkg/registry/generic
- pkg/registry/thirdpartyresourcedata - pkg/registry/thirdpartyresourcedata
- pkg/runtime - pkg/runtime
- pkg/runtime/serializer - pkg/runtime/serializer
@ -560,15 +485,8 @@ imports:
- pkg/security/podsecuritypolicy/util - pkg/security/podsecuritypolicy/util
- pkg/selection - pkg/selection
- pkg/storage - pkg/storage
- pkg/storage/etcd
- pkg/storage/etcd/metrics
- pkg/storage/etcd/util
- pkg/storage/etcd3
- pkg/storage/storagebackend
- pkg/storage/storagebackend/factory
- pkg/types - pkg/types
- pkg/util - pkg/util
- pkg/util/cache
- pkg/util/certificates - pkg/util/certificates
- pkg/util/clock - pkg/util/clock
- pkg/util/config - pkg/util/config

Loading…
Cancel
Save