diff options
author | Torstein Egge <torstein.egge@yahooinc.com> | 2023-06-23 13:38:32 +0200 |
---|---|---|
committer | Torstein Egge <torstein.egge@yahooinc.com> | 2023-06-26 13:32:51 +0200 |
commit | 4236cd87701608ed076060c962a756df294e783c (patch) | |
tree | 6579f2c6ca7d6cdc2c1b7e84eca4c597087f9f57 /client/go | |
parent | 0c341f8ed39b3edcd1938d964cbdf9ce7c179411 (diff) |
Implement command to generate markdown files from --help pages
Diffstat (limited to 'client/go')
-rw-r--r-- | client/go/internal/cli/cmd/gendoc.go | 29 | ||||
-rw-r--r-- | client/go/internal/cli/cmd/root.go | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/client/go/internal/cli/cmd/gendoc.go b/client/go/internal/cli/cmd/gendoc.go new file mode 100644 index 00000000000..70d166bb9ce --- /dev/null +++ b/client/go/internal/cli/cmd/gendoc.go @@ -0,0 +1,29 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/spf13/cobra/doc" +) + +func newGendocCmd(cli *CLI) *cobra.Command { + return &cobra.Command{ + Use: "gendoc directory", + Short: "Generate documentation from '--help' pages and write as markdown files to a given directory", + Args: cobra.ExactArgs(1), + Hidden: true, // Not intended to be called by users + DisableAutoGenTag: true, + SilenceUsage: true, + RunE: func(cmd *cobra.Command, args []string) error { + dir := args[0] + err := doc.GenMarkdownTree(cli.cmd, dir) + if err != nil { + return fmt.Errorf("failed to write documentation pages: %w", err) + } + cli.printSuccess("Documentation pages written to ", dir) + return nil + }, + } +} diff --git a/client/go/internal/cli/cmd/root.go b/client/go/internal/cli/cmd/root.go index 41de0bfc9d3..5aa345cd8e4 100644 --- a/client/go/internal/cli/cmd/root.go +++ b/client/go/internal/cli/cmd/root.go @@ -264,6 +264,7 @@ func (c *CLI) configureCommands() { rootCmd.AddCommand(documentCmd) // document rootCmd.AddCommand(newLogCmd(c)) // log rootCmd.AddCommand(newManCmd(c)) // man + rootCmd.AddCommand(newGendocCmd(c)) // gendoc prodCmd.AddCommand(newProdInitCmd(c)) // prod init prodCmd.AddCommand(newProdDeployCmd(c)) // prod deploy rootCmd.AddCommand(prodCmd) // prod |