Skip to content

Commit

Permalink
docs command --help formatting and error handling for supplied path i…
Browse files Browse the repository at this point in the history
…n docs command.

Signed-off-by: tobigiwa <giwaoluwatobi@gmail.com>
  • Loading branch information
tobigiwa committed Sep 19, 2023
1 parent 9073136 commit 20d8fbd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
package cmd

import (
"errors"
"fmt"
"io/fs"
"os"

"github.com/spf13/cobra"
Expand All @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 20d8fbd

Please sign in to comment.