github.com/Beeketing/helm@v2.12.1+incompatible/cmd/helm/docs.go (about) 1 /* 2 Copyright The Helm Authors. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 package main 17 18 import ( 19 "fmt" 20 "io" 21 "path/filepath" 22 23 "github.com/spf13/cobra" 24 "github.com/spf13/cobra/doc" 25 ) 26 27 const docsDesc = ` 28 Generate documentation files for Helm. 29 30 This command can generate documentation for Helm in the following formats: 31 32 - Markdown 33 - Man pages 34 35 It can also generate bash autocompletions. 36 37 $ helm docs markdown -dir mydocs/ 38 ` 39 40 type docsCmd struct { 41 out io.Writer 42 dest string 43 docTypeString string 44 topCmd *cobra.Command 45 } 46 47 func newDocsCmd(out io.Writer) *cobra.Command { 48 dc := &docsCmd{out: out} 49 50 cmd := &cobra.Command{ 51 Use: "docs", 52 Short: "Generate documentation as markdown or man pages", 53 Long: docsDesc, 54 Hidden: true, 55 RunE: func(cmd *cobra.Command, args []string) error { 56 dc.topCmd = cmd.Root() 57 return dc.run() 58 }, 59 } 60 61 f := cmd.Flags() 62 f.StringVar(&dc.dest, "dir", "./", "directory to which documentation is written") 63 f.StringVar(&dc.docTypeString, "type", "markdown", "the type of documentation to generate (markdown, man, bash)") 64 65 return cmd 66 } 67 68 func (d *docsCmd) run() error { 69 switch d.docTypeString { 70 case "markdown", "mdown", "md": 71 return doc.GenMarkdownTree(d.topCmd, d.dest) 72 case "man": 73 manHdr := &doc.GenManHeader{Title: "HELM", Section: "1"} 74 return doc.GenManTree(d.topCmd, manHdr, d.dest) 75 case "bash": 76 return d.topCmd.GenBashCompletionFile(filepath.Join(d.dest, "completions.bash")) 77 default: 78 return fmt.Errorf("unknown doc type %q. Try 'markdown' or 'man'", d.docTypeString) 79 } 80 }