Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example to readme #3

Merged
merged 4 commits into from
Jul 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 78 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,81 @@
[![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.
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...]
```

````
Loading