urfave/cli-docs/v3 is an extended documentation library for use with urfave/cli/v3.
- Add the dependency to your project
go get github.com/urfave/cli-docs/v3@latest- Add it as import
import (
+ docs "github.com/urfave/cli-docs/v3"
)- Now use it e.g. to generate markdown document from a command
package main
import (
"context""fmt""os"
docs "github.com/urfave/cli-docs/v3"
cli "github.com/urfave/cli/v3"
)
funcmain() {
app:=&cli.Command{
Name: "greet",
Usage: "say a greeting",
Action: func(ctx context.Context, c*cli.Command) error {
fmt.Println("Greetings")
returnnil
},
}
md, err:=docs.ToMarkdown(app)
iferr!=nil {
panic(err)
}
fi, err:=os.Create("cli-docs.md")
iferr!=nil {
panic(err)
}
deferfi.Close()
if_, err:=fi.WriteString("# CLI\n\n"+md); err!=nil {
panic(err)
}
}This will create a file cli-docs.md with content:
# CLI# NAME
greet - say a greeting
# SYNOPSIS
greet
**Usage**:
```greet [GLOBAL OPTIONS] [command [COMMAND OPTIONS]] [ARGUMENTS...]```Some examples of the cli generated using this markdown