From cc48f795896d59aa35e43d624cc3c79753202a9d Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Mon, 18 Sep 2023 14:04:00 -0400 Subject: [PATCH] Update usage and long help for command. --- cmd/provenanced/cmd/docgen.go | 67 +++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/cmd/provenanced/cmd/docgen.go b/cmd/provenanced/cmd/docgen.go index a30b01c5df..ae754bcf01 100644 --- a/cmd/provenanced/cmd/docgen.go +++ b/cmd/provenanced/cmd/docgen.go @@ -20,53 +20,68 @@ const ( func GetDocGenCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "docgen", - Short: "Generates cli documentation for the Provenance Blockchain.", - Long: "", + Use: "docgen (--markdown) (--yaml) (--rest) (--manpages) [flags]", + Short: "Generates cli documentation for the Provenance Blockchain.", + Long: `Generates cli documentation for the Provenance Blockchain. +Various documentation formats can be generated, including markdown, YAML, REST, and man pages. +To ensure the command's success, you must specify at least one format. +A successful command will not only generate files in the selected formats but also create the target directory if it doesn't already exist.`, Example: fmt.Sprintf("%s '/tmp' --yaml --markdown", docGenCmdStart), Hidden: true, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - dir := args[0] - if !exists(dir) { - err := os.Mkdir(dir, 0755) - if err != nil { - return err - } - } - - // Check if at least one flag is enabled - markdown, err := cmd.Flags().GetBool(FlagMarkdown) if err != nil { return err } - if markdown { - doc.GenMarkdownTree(cmd.Root(), dir) - } - yaml, err := cmd.Flags().GetBool(FlagYaml) if err != nil { return err } - if yaml { - doc.GenYamlTree(cmd.Root(), dir) - } - rest, err := cmd.Flags().GetBool(FlagRest) if err != nil { return err } - if rest { - doc.GenReSTTree(cmd.Root(), dir) - } - manpage, err := cmd.Flags().GetBool(FlagManpage) if err != nil { return err } + + if !markdown && !yaml && !rest && !manpage { + return fmt.Errorf("at least one doc type must be specified.") + } + + dir := args[0] + if !exists(dir) { + err := os.Mkdir(dir, 0755) + if err != nil { + return err + } + } + + if markdown { + err = doc.GenMarkdownTree(cmd.Root(), dir) + if err != nil { + return err + } + } + if yaml { + err = doc.GenYamlTree(cmd.Root(), dir) + if err != nil { + return err + } + } + if rest { + err = doc.GenReSTTree(cmd.Root(), dir) + if err != nil { + return err + } + } if manpage { - doc.GenManTree(cmd.Root(), nil, dir) + err = doc.GenManTree(cmd.Root(), nil, dir) + if err != nil { + return err + } } return nil