Skip to content

Commit

Permalink
Add sub command for completion and documentation generation
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Sowitzki <[email protected]>
  • Loading branch information
Alexander Sowitzki committed Jun 7, 2019
1 parent 5f8a9f9 commit 335311d
Show file tree
Hide file tree
Showing 28 changed files with 7,007 additions and 12 deletions.
35 changes: 31 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ required = [
name = "k8s.io/code-generator"
non-go = false
go-tests = false
unused-packages = false
unused-packages = false
[[constraint]]
name = "github.com/cpuguy83/go-md2man"
revision = "691ee98543af2f262f35fbb54bdd42f00b9b9cc5"
79 changes: 79 additions & 0 deletions pkg/cmd/packaging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright 2019 The KubeOne Authors.
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 cmd

import (
"os"

"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

func completionCmd(rootCmd *cobra.Command) *cobra.Command {
var cmd = &cobra.Command{
Use: "completion <bash|zsh>",
Short: "Generates completion scripts for bash and zsh",
Long: `To load completion run into your current shell run
. <(kubeone bashCompletion <shell>)
`,
Example: "kubeone completion bash",
ValidArgs: []string{"bash", "zsh"},
Args: cobra.ExactValidArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
switch args[0] {
case "bash":
err = rootCmd.GenBashCompletion(os.Stdout)
case "zsh":
err = rootCmd.GenZshCompletion(os.Stdout)
}
return
},
}
return cmd
}

func docCmd(rootCmd *cobra.Command) *cobra.Command {
var path string
var cmd = &cobra.Command{
Use: "doc <man|md|rest|yaml>",
Short: "Generates documentation",
Long: "Generation can be generated as Man Pages, Markdown, ReStructured Text Docs or Yaml",
Example: "kubeone completion bash",
ValidArgs: []string{"man", "md", "rest", "yaml"},
Args: cobra.ExactValidArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
switch args[0] {
case "man":
header := &doc.GenManHeader{
Title: "KubeOne",
Section: "1",
}
err = doc.GenManTree(rootCmd, header, path)
case "md":
err = doc.GenMarkdownTree(rootCmd, path)
case "rest":
err = doc.GenReSTTree(rootCmd, path)
case "yaml":
err = doc.GenYamlTree(rootCmd, path)
}
return
},
}
cmd.Flags().StringVarP(&path, "output-dir", "o", "/tmp/", "Directory to populate with documentation")
return cmd
}
2 changes: 2 additions & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func newRoot() *cobra.Command {
kubeconfigCmd(fs),
configCmd(fs),
versionCmd(fs),
completionCmd(rootCmd),
docCmd(rootCmd),
)

return rootCmd
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/cpuguy83/go-md2man/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/cpuguy83/go-md2man/md2man/md2man.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 335311d

Please sign in to comment.