From 2ee3e46d4346b048dae6c27bde59bd33deae532b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 13 Jul 2024 21:46:18 +0200 Subject: [PATCH 1/4] add example to readme --- README.md | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 817f481..c34614e 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,41 @@ [![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 docu from a command + +```go +func main() { + app := newApp() + 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) + } +} +``` From 944ca255b20d801534541e7064ae82fdde90104d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 14 Jul 2024 12:16:43 +0200 Subject: [PATCH 2/4] Update README.md Co-authored-by: Eng Zer Jun --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c34614e..b99bf81 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ urfave/cli-docs/v3 is an extended documentation library for use with urfave/cli/ ) ``` -3. Now use it e.g. to generate markdown docu from a command +3. Now use it e.g. to generate markdown document from a command ```go func main() { From 71d54df3064d653d1a3b966f4dc34b695ffd902b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 14 Jul 2024 12:32:21 +0200 Subject: [PATCH 3/4] add suggestion --- README.md | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b99bf81..2d425bd 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,26 @@ urfave/cli-docs/v3 is an extended documentation library for use with urfave/cli/ 3. Now use it e.g. to generate markdown document from a command ```go +package main + +import ( + "fmt" + "os" + + docs "github.com/urfave/cli-docs/v3" + cli "github.com/urfave/cli/v3" +) + func main() { - app := newApp() + app := &cli.Command{ + Name: "greet", + Usage: "say a greeting", + Action: func(c *cli.Context) error { + fmt.Println("Greetings") + return nil + }, + } + md, err := docs.ToMarkdown(app) if err != nil { panic(err) @@ -42,3 +60,23 @@ func main() { } } ``` + +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...] +``` +```` From 9702f7048e118af2e15163de861c6aae3ac13cb0 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 14 Jul 2024 12:41:02 +0200 Subject: [PATCH 4/4] fix example and use actual output --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d425bd..e2a74de 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ urfave/cli-docs/v3 is an extended documentation library for use with urfave/cli/ package main import ( + "context" "fmt" "os" @@ -39,7 +40,7 @@ func main() { app := &cli.Command{ Name: "greet", Usage: "say a greeting", - Action: func(c *cli.Context) error { + Action: func(ctx context.Context, c *cli.Command) error { fmt.Println("Greetings") return nil }, @@ -79,4 +80,5 @@ greet ``` greet [GLOBAL OPTIONS] [command [COMMAND OPTIONS]] [ARGUMENTS...] ``` + ````