Skip to content

Commit

Permalink
Add sub command for completion and documentation generation (#484)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Sowitzki <[email protected]>
  • Loading branch information
Alexander Sowitzki authored and kubermatic-bot committed Jun 11, 2019
1 parent 5f8a9f9 commit 91fa3c9
Show file tree
Hide file tree
Showing 29 changed files with 7,018 additions and 13 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"
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on-prem or bare-metal cluster.

## Project Status

As of v0.6.0, KubeOne is in the beta phase. Check out the
As of v0.6.0, KubeOne is in the beta phase. Check out the
[Backwards Compatibility Policy][6] for more details on
backwards compatibility, KubeOne versioning, and maturity of each KubeOne
component.
Expand Down Expand Up @@ -66,6 +66,16 @@ KubeOne.
make install
```

To install completions for bash (zsh also available), run or put this command into your .bashrc file:
```bash
. <(kubeone completion bash)
```

To generate documentation (man pages for example, more available), run:
```bash
kubeone document man -o /tmp/man
```

## Kubernetes Versions Compatibility

Each KubeOne version is supposed to support and work with a set of Kubernetes
Expand Down
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 completion <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 documentCmd(rootCmd *cobra.Command) *cobra.Command {
var path string
var cmd = &cobra.Command{
Use: "document <man|md|rest|yaml>",
Short: "Generates documentation",
Long: "Documentation can be generated as man pages, markdown, restructured text docs or yaml",
Example: "kubeone document man",
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),
documentCmd(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 91fa3c9

Please sign in to comment.