From 20d8fbdf4b524935f3b68b7d0ebe69c290030b69 Mon Sep 17 00:00:00 2001 From: tobigiwa Date: Tue, 19 Sep 2023 01:55:55 -0400 Subject: [PATCH] docs command --help formatting and error handling for supplied path in docs command. Signed-off-by: tobigiwa --- cmd/docs.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/docs.go b/cmd/docs.go index 70ea5486..984045ea 100644 --- a/cmd/docs.go +++ b/cmd/docs.go @@ -4,7 +4,9 @@ Copyright © 2023 NAME HERE package cmd import ( + "errors" "fmt" + "io/fs" "os" "github.com/spf13/cobra" @@ -16,9 +18,9 @@ var docsCmd = &cobra.Command{ Use: "docs", Short: "Generate markdown docs", Long: `Generate markdown docs for the entire command tree. - - The command takes an optional argument specifying directory to put the - generated documentation, default is "{cwd}/docs/command_docs/"`, + +The command takes an optional argument specifying directory to put the +generated documentation, default is "{cwd}/docs/command_docs/"`, RunE: func(cmd *cobra.Command, args []string) error { var path string @@ -33,6 +35,10 @@ var docsCmd = &cobra.Command{ } } else { path = args[0] + if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) || err != nil { + err = fmt.Errorf("path you supplied for documentation is invalid: %v", err) + return err + } } err := doc.GenMarkdownTree(rootCmd, path)