Skip to content

Commit

Permalink
Merge pull request #263 from tobigiwa/tobytobias#new_feature
Browse files Browse the repository at this point in the history
New feature (docs command)
  • Loading branch information
nguyer authored Jan 12, 2024
2 parents 311edc5 + b07b117 commit 1e894ee
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ ff/ff
dist/
*.iml
.idea/
docs/command_docs
55 changes: 55 additions & 0 deletions cmd/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright © 2023 Giwa Oluwatobi <[email protected]>
*/
package cmd

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

"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

// docsCmd represents the docs command
var docsCmd = &cobra.Command{
Use: "docs [dir]",
Short: "Generate markdown documentation for all command",
Args: cobra.MaximumNArgs(1),
Long: `Generate markdown documentation for the entire command tree.
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

if len(args) == 0 {
currentWoringDir, err := os.Getwd()
if err != nil {
return err
}
path = fmt.Sprintf("%s/docs/command_docs", currentWoringDir)
if err := os.MkdirAll(path, 0755); err != nil {
return err
}
} 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)
if err != nil {
return err
}
return nil
},
}

func init() {
rootCmd.AddCommand(docsCmd)
}
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down Expand Up @@ -806,6 +807,7 @@ github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBO
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
Expand Down

0 comments on commit 1e894ee

Please sign in to comment.