From 07877ab137c5ca8f27765ffd39a6467b3033d690 Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Fri, 15 Sep 2023 15:56:31 -0400 Subject: [PATCH] Added additional logic. --- cmd/provenanced/cmd/docgen.go | 42 ++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/cmd/provenanced/cmd/docgen.go b/cmd/provenanced/cmd/docgen.go index c08bb7de03..a30b01c5df 100644 --- a/cmd/provenanced/cmd/docgen.go +++ b/cmd/provenanced/cmd/docgen.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/cosmos/cosmos-sdk/version" "github.com/spf13/cobra" @@ -26,12 +27,46 @@ func GetDocGenCmd() *cobra.Command { 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(), args[0]) + 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 manpage { + doc.GenManTree(cmd.Root(), nil, dir) } return nil @@ -45,3 +80,8 @@ func GetDocGenCmd() *cobra.Command { return cmd } + +func exists(dir string) bool { + _, err := os.Stat(dir) + return err == nil +}