From 4236cd87701608ed076060c962a756df294e783c Mon Sep 17 00:00:00 2001 From: Torstein Egge Date: Fri, 23 Jun 2023 13:38:32 +0200 Subject: Implement command to generate markdown files from --help pages --- client/go/internal/cli/cmd/gendoc.go | 29 +++++++++++++++++++++++++++++ client/go/internal/cli/cmd/root.go | 1 + 2 files changed, 30 insertions(+) create mode 100644 client/go/internal/cli/cmd/gendoc.go (limited to 'client/go/internal/cli/cmd') 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 -- cgit v1.2.3