File: README.md

package info (click to toggle)
golang-github-urfave-cli-docs-v3 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 172 kB
  • sloc: makefile: 16
file content (84 lines) | stat: -rw-r--r-- 1,683 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Welcome to urfave/cli-docs/v3

[![Run Tests](https://github.com/urfave/cli-docs/actions/workflows/main.yml/badge.svg)](https://github.com/urfave/cli-docs/actions/workflows/main.yml)
[![Go Reference](https://pkg.go.dev/badge/github.com/urfave/cli-docs/v3.svg)](https://pkg.go.dev/github.com/urfave/cli-docs/v3)
[![Go Report Card](https://goreportcard.com/badge/github.com/urfave/cli-docs/v3)](https://goreportcard.com/report/github.com/urfave/cli-docs/v3)

urfave/cli-docs/v3 is an extended documentation library for use with urfave/cli/v3.

## Start using

1. Add the dependency to your project

```sh
 go get github.com/urfave/cli-docs/v3@latest
 ```

2. Add it as import

```diff
 import (
+  docs "github.com/urfave/cli-docs/v3"
 )
```

3. Now use it e.g. to generate markdown document from a command

```go
package main

import (
    "context"
    "fmt"
    "os"

    docs "github.com/urfave/cli-docs/v3"
    cli "github.com/urfave/cli/v3"
)

func main() {
    app := &cli.Command{
        Name:  "greet",
        Usage: "say a greeting",
        Action: func(ctx context.Context, c *cli.Command) error {
            fmt.Println("Greetings")
            return nil
        },
    }

    md, err := docs.ToMarkdown(app)
    if err != nil {
        panic(err)
    }

    fi, err := os.Create("cli-docs.md")
    if err != nil {
        panic(err)
    }
    defer fi.Close()
    if _, err := fi.WriteString("# CLI\n\n" + md); err != nil {
        panic(err)
    }
}
```

This will create a file `cli-docs.md` with content:

````md
# CLI

# NAME

greet - say a greeting

# SYNOPSIS

greet

**Usage**:

```
greet [GLOBAL OPTIONS] [command [COMMAND OPTIONS]] [ARGUMENTS...]
```

````