File tree 1 file changed +78
-2
lines changed
1 file changed +78
-2
lines changed Original file line number Diff line number Diff line change 4
4
[ ![ Go Reference] ( https://pkg.go.dev/badge/github.com/urfave/cli-docs/v3.svg )] ( https://pkg.go.dev/github.com/urfave/cli-docs/v3 )
5
5
[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/urfave/cli-docs/v3 )] ( https://goreportcard.com/report/github.com/urfave/cli-docs/v3 )
6
6
7
- urfave/cli-docs/v3 is an extended documentation library for use
8
- with urfave/cli/v3.
7
+ urfave/cli-docs/v3 is an extended documentation library for use with urfave/cli/v3.
8
+
9
+ ## Start using
10
+
11
+ 1 . Add the dependency to your project
12
+
13
+ ``` sh
14
+ go get github.com/urfave/cli-docs/v3@latest
15
+ ```
16
+
17
+ 2 . Add it as import
18
+
19
+ ``` diff
20
+ import (
21
+ + docs "github.com/urfave/cli-docs/v3"
22
+ )
23
+ ```
24
+
25
+ 3 . Now use it e.g. to generate markdown document from a command
26
+
27
+ ``` go
28
+ package main
29
+
30
+ import (
31
+ " context"
32
+ " fmt"
33
+ " os"
34
+
35
+ docs " github.com/urfave/cli-docs/v3"
36
+ cli " github.com/urfave/cli/v3"
37
+ )
38
+
39
+ func main () {
40
+ app := &cli.Command {
41
+ Name: " greet" ,
42
+ Usage: " say a greeting" ,
43
+ Action: func (ctx context.Context , c *cli.Command ) error {
44
+ fmt.Println (" Greetings" )
45
+ return nil
46
+ },
47
+ }
48
+
49
+ md , err := docs.ToMarkdown (app)
50
+ if err != nil {
51
+ panic (err)
52
+ }
53
+
54
+ fi , err := os.Create (" cli-docs.md" )
55
+ if err != nil {
56
+ panic (err)
57
+ }
58
+ defer fi.Close ()
59
+ if _ , err := fi.WriteString (" # CLI\n\n " + md); err != nil {
60
+ panic (err)
61
+ }
62
+ }
63
+ ```
64
+
65
+ This will create a file ` cli-docs.md ` with content:
66
+
67
+ ```` md
68
+ # CLI
69
+
70
+ # NAME
71
+
72
+ greet - say a greeting
73
+
74
+ # SYNOPSIS
75
+
76
+ greet
77
+
78
+ **Usage**:
79
+
80
+ ```
81
+ greet [GLOBAL OPTIONS] [command [COMMAND OPTIONS]] [ARGUMENTS...]
82
+ ```
83
+
84
+ ````
You can’t perform that action at this time.
0 commit comments