Skip to content

Commit 1da0091

Browse files
6543Juneezee
andauthored
docs: add example to README (#3)
Co-authored-by: Eng Zer Jun <[email protected]>
1 parent 07c2cad commit 1da0091

File tree

1 file changed

+78
-2
lines changed

1 file changed

+78
-2
lines changed

README.md

+78-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,81 @@
44
[![Go Reference](https://pkg.go.dev/badge/github.com/urfave/cli-docs/v3.svg)](https://pkg.go.dev/github.com/urfave/cli-docs/v3)
55
[![Go Report Card](https://goreportcard.com/badge/github.com/urfave/cli-docs/v3)](https://goreportcard.com/report/github.com/urfave/cli-docs/v3)
66

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+
````

0 commit comments

Comments
 (0)