-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sub command for completion and documentation generation
Signed-off-by: Alexander Sowitzki <[email protected]>
- Loading branch information
Alexander Sowitzki
committed
Jun 7, 2019
1 parent
5f8a9f9
commit 335311d
Showing
28 changed files
with
7,007 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.