Skip to content

Commit 25a804a

Browse files
committed
Add usage documentation
1 parent 439c22d commit 25a804a

16 files changed

+202
-11
lines changed

Justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ clean:
99

1010
run *commands:
1111
go run main.go {{commands}}
12+
13+
cobra-docs:
14+
go run docs/gen_docs.go

cmd/chat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ If '-q' is not specified, the user will be prompted to enter a question.
5555
}
5656

5757
func init() {
58-
rootCmd.AddCommand(chatCmd)
58+
RootCmd.AddCommand(chatCmd)
5959

6060
chatCmd.Flags().StringVarP(&question, "question", "q", "", "Question to chat ChatGPT")
6161
}

cmd/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ var docCmd = &cobra.Command{
7979
}
8080

8181
func init() {
82-
rootCmd.AddCommand(docCmd)
82+
RootCmd.AddCommand(docCmd)
8383

8484
// see cmd/vars.go for the definition of these flags
8585
docCmd.Flags().StringVarP(&filePath, "file", "f", "", "The file to document")

cmd/docs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ search for files in the directory and document them.
135135
}
136136

137137
func init() {
138-
rootCmd.AddCommand(docsCmd)
138+
RootCmd.AddCommand(docsCmd)
139139

140140
// see cmd/vars for the definition of these flags
141141
docsCmd.Flags().StringVarP(&chatPrompt, "prompt", "p", "", "Prompt to use for the ChatGPT API")

cmd/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ This API key will be used to authenticate with the OpenAI ChatGPT API.`,
4242
}
4343

4444
func init() {
45-
rootCmd.AddCommand(loginCmd)
45+
RootCmd.AddCommand(loginCmd)
4646

4747
loginCmd.Flags().StringVarP(&apiKey, "apikey", "k", "", "API key to add to configuration")
4848
}

cmd/prompt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var promptCmd = &cobra.Command{
7878
}
7979

8080
func init() {
81-
rootCmd.AddCommand(promptCmd)
81+
RootCmd.AddCommand(promptCmd)
8282

8383
// see cmd/vars.go for the definition of these flags
8484
promptCmd.Flags().StringVarP(&preambleFile, "preamble", "p", "", "path to preamble text file")

cmd/root.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
// rootCmd represents the base command when called without any subcommands
13-
var rootCmd = &cobra.Command{
12+
// RootCmd represents the base command when called without any subcommands
13+
var RootCmd = &cobra.Command{
1414
Use: "otto",
1515
Short: "Document your code with ease",
1616
Long: `Code documentation made easy using GPT.`,
@@ -20,9 +20,9 @@ var rootCmd = &cobra.Command{
2020
}
2121

2222
// Execute adds all child commands to the root command and sets flags appropriately.
23-
// This is called by main.main(). It only needs to happen once to the rootCmd.
23+
// This is called by main.main(). It only needs to happen once to the RootCmd.
2424
func Execute() {
25-
err := rootCmd.Execute()
25+
err := RootCmd.Execute()
2626
if err != nil {
2727
os.Exit(1)
2828
}
@@ -33,9 +33,9 @@ func init() {
3333
// Cobra supports persistent flags, which, if defined here,
3434
// will be global for your application.
3535

36-
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.ottodocs.yaml)")
36+
// RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.ottodocs.yaml)")
3737

3838
// Cobra also supports local flags, which will only run
3939
// when this action is called directly.
40-
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
40+
// RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
4141
}

docs/gen_docs.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"github.com/chand1012/ottodocs/cmd"
5+
"github.com/spf13/cobra/doc"
6+
)
7+
8+
func main() {
9+
err := doc.GenMarkdownTree(cmd.RootCmd, "./docs")
10+
if err != nil {
11+
panic(err)
12+
}
13+
}

docs/otto.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## otto
2+
3+
Document your code with ease
4+
5+
### Synopsis
6+
7+
Code documentation made easy using GPT.
8+
9+
### Options
10+
11+
```
12+
-h, --help help for otto
13+
```
14+
15+
### SEE ALSO
16+
17+
* [otto chat](otto_chat.md) - Ask ChatGPT a question from the command line.
18+
* [otto doc](otto_doc.md) - Document a file
19+
* [otto docs](otto_docs.md) - Document a repository of files
20+
* [otto login](otto_login.md) - Add an API key to your configuration
21+
* [otto prompt](otto_prompt.md) - Generates a ChatGPT prompt from a given Git repo
22+
23+
###### Auto generated by spf13/cobra on 18-Mar-2023

docs/otto_chat.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## otto chat
2+
3+
Ask ChatGPT a question from the command line.
4+
5+
### Synopsis
6+
7+
Ask ChatGPT a question from the command line.
8+
9+
If '-q' is not specified, the user will be prompted to enter a question.
10+
11+
12+
```
13+
otto chat [flags]
14+
```
15+
16+
### Options
17+
18+
```
19+
-h, --help help for chat
20+
-q, --question string Question to chat ChatGPT
21+
```
22+
23+
### SEE ALSO
24+
25+
* [otto](otto.md) - Document your code with ease
26+
27+
###### Auto generated by spf13/cobra on 18-Mar-2023

docs/otto_doc.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## otto doc
2+
3+
Document a file
4+
5+
### Synopsis
6+
7+
Document a file using the OpenAI ChatGPT API.
8+
9+
```
10+
otto doc [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-f, --file string The file to document
17+
-h, --help help for doc
18+
-i, --inline Inline mode. Adds the documentation to the code.
19+
-m, --markdown Markdown mode. Outputs the documentation in markdown.
20+
-o, --output string The output file to write the documentation to.
21+
-w, --overwrite Overwrite the original file.
22+
-p, --prompt string The prompt to use for the document
23+
```
24+
25+
### SEE ALSO
26+
27+
* [otto](otto.md) - Document your code with ease
28+
29+
###### Auto generated by spf13/cobra on 18-Mar-2023

docs/otto_docs.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## otto docs
2+
3+
Document a repository of files
4+
5+
### Synopsis
6+
7+
Document an entire repository of files. Specify the path to the repo as the first positional argument. This command will recursively
8+
search for files in the directory and document them.
9+
10+
11+
```
12+
otto docs [flags]
13+
```
14+
15+
### Options
16+
17+
```
18+
-h, --help help for docs
19+
-n, --ignore string path to .gptignore file
20+
-g, --ignore-gitignore ignore .gitignore file
21+
-i, --inline Output in inline format
22+
-m, --markdown Output in Markdown format
23+
-o, --output string Path to the output file. For use with --markdown
24+
-w, --overwrite Overwrite the original file
25+
-p, --prompt string Prompt to use for the ChatGPT API
26+
```
27+
28+
### SEE ALSO
29+
30+
* [otto](otto.md) - Document your code with ease
31+
32+
###### Auto generated by spf13/cobra on 18-Mar-2023

docs/otto_login.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## otto login
2+
3+
Add an API key to your configuration
4+
5+
### Synopsis
6+
7+
Add an API key to your configuration.
8+
This API key will be used to authenticate with the OpenAI ChatGPT API.
9+
10+
```
11+
otto login [flags]
12+
```
13+
14+
### Options
15+
16+
```
17+
-k, --apikey string API key to add to configuration
18+
-h, --help help for login
19+
```
20+
21+
### SEE ALSO
22+
23+
* [otto](otto.md) - Document your code with ease
24+
25+
###### Auto generated by spf13/cobra on 18-Mar-2023

docs/otto_prompt.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## otto prompt
2+
3+
Generates a ChatGPT prompt from a given Git repo
4+
5+
### Synopsis
6+
7+
Generates a ChatGPT prompt from a given Git repo. Specify the path to the repo as the first positional argument.
8+
9+
```
10+
otto prompt [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-e, --estimate estimate the number of tokens in the output
17+
-h, --help help for prompt
18+
-i, --ignore string path to .gptignore file
19+
-g, --ignore-gitignore ignore .gitignore file
20+
-j, --json output JSON
21+
-o, --output string path to output file
22+
-p, --preamble string path to preamble text file
23+
```
24+
25+
### SEE ALSO
26+
27+
* [otto](otto.md) - Document your code with ease
28+
29+
###### Auto generated by spf13/cobra on 18-Mar-2023

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ require (
1010
)
1111

1212
require (
13+
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
1314
github.com/dlclark/regexp2 v1.8.1 // indirect
1415
github.com/dop251/goja v0.0.0-20230304130813-e2f543bf4b4c // indirect
1516
github.com/dop251/goja_nodejs v0.0.0-20230226152057-060fa99b809f // indirect
1617
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
1718
github.com/gobwas/glob v0.2.3 // indirect
1819
github.com/google/pprof v0.0.0-20230309165930-d61513b1440d // indirect
1920
github.com/inconshreveable/mousetrap v1.0.1 // indirect
21+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
2022
github.com/spf13/pflag v1.0.5 // indirect
2123
golang.org/x/text v0.8.0 // indirect
24+
gopkg.in/yaml.v3 v3.0.1 // indirect
2225
)

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ github.com/chand1012/git2gpt v0.3.0/go.mod h1:tT4D74zqhWjDkQCyYqmEclIhOqI3t+hEmU
55
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
66
github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic=
77
github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
8+
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
89
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
910
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1011
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
@@ -31,13 +32,17 @@ github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7P
3132
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
3233
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
3334
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
35+
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
3436
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
3537
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
3638
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
39+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
3740
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
3841
github.com/pandodao/tokenizer-go v0.1.0 h1:HYqwps+MVriDeVKvtQH19fsQcR9F2z5wgYXNxSL0o6g=
3942
github.com/pandodao/tokenizer-go v0.1.0/go.mod h1:ln+rU29YAhh7JcdlJWNt/ah6XrAzW6+LUE7DRcLoIdk=
43+
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
4044
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
45+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
4146
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
4247
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
4348
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
@@ -77,8 +82,10 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
7782
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
7883
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7984
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
85+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
8086
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
8187
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
8288
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
8389
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
90+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
8491
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)