README.md

  1# mango
  2
  3[![Build Status](https://github.com/muesli/mango/workflows/build/badge.svg)](https://github.com/muesli/mango/actions)
  4[![Go ReportCard](https://goreportcard.com/badge/muesli/mango)](https://goreportcard.com/report/muesli/mango)
  5[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://pkg.go.dev/github.com/muesli/mango)
  6
  7mango is a man-page generator for the Go flag, pflag, cobra, and coral packages.
  8It extracts commands, flags, and arguments from your program and enables it to
  9self-document.
 10
 11## Adapters
 12
 13Currently the following adapters exist:
 14
 15- flag: support for Go's standard flag package
 16- [mango-cobra](https://github.com/muesli/mango-cobra): an adapter for [cobra](https://github.com/spf13/cobra)
 17- [mango-coral](https://github.com/muesli/mango-coral): an adapter for [coral](https://github.com/muesli/coral)
 18- [mango-pflag](https://github.com/muesli/mango-pflag): an adapter for the [pflag](https://github.com/spf13/pflag) package
 19
 20## Usage with flag:
 21
 22```go
 23import (
 24    "flag"
 25    "fmt"
 26
 27    "github.com/muesli/mango"
 28    "github.com/muesli/mango/mflag"
 29    "github.com/muesli/roff"
 30)
 31
 32var (
 33    one = flag.String("one", "", "first value")
 34    two = flag.String("two", "", "second value")
 35)
 36
 37func main() {
 38    flag.Parse()
 39
 40    manPage := mango.NewManPage(1, "mango", "mango - a man-page generator").
 41        WithLongDescription("mango is a man-page generator for Go.\n"+
 42            "Features:\n"+
 43            "* User-friendly\n"+
 44            "* Plugable").
 45        WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+
 46            "Released under MIT license.")
 47
 48    flag.VisitAll(mflag.FlagVisitor(manPage))
 49    fmt.Println(manPage.Build(roff.NewDocument()))
 50}
 51```
 52
 53Mango will extract all the flags from your app and generate a man-page similar
 54to this example:
 55
 56![mango](/mango.png)
 57
 58## Usage with pflag:
 59
 60```go
 61import (
 62    "fmt"
 63
 64    "github.com/muesli/mango"
 65    mpflag "github.com/muesli/mango-pflag"
 66    "github.com/muesli/roff"
 67    flag "github.com/spf13/pflag"
 68)
 69
 70func main() {
 71    flag.Parse()
 72
 73    manPage := mango.NewManPage(1, "mango", "mango - a man-page generator").
 74        WithLongDescription("mango is a man-page generator for Go.").
 75        WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+
 76            "Released under MIT license.")
 77
 78    flag.VisitAll(mpflag.PFlagVisitor(manPage))
 79    fmt.Println(manPage.Build(roff.NewDocument()))
 80}
 81```
 82
 83## Usage with cobra:
 84
 85```go
 86import (
 87	"fmt"
 88
 89	mcobra "github.com/muesli/mango-cobra"
 90	"github.com/muesli/roff"
 91	"github.com/spf13/cobra"
 92)
 93
 94var (
 95    rootCmd = &cobra.Command{
 96        Use:   "mango",
 97        Short: "A man-page generator",
 98    }
 99)
100
101func main() {
102    manPage, err := mcobra.NewManPage(1, rootCmd)
103    if err != nil {
104        panic(err)
105    }
106
107    manPage = manPage.WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+
108        "Released under MIT license.")
109
110    fmt.Println(manPage.Build(roff.NewDocument()))
111}
112```
113
114## Usage with coral:
115
116```go
117import (
118	"fmt"
119
120	mcoral "github.com/muesli/mango-coral"
121	"github.com/muesli/roff"
122	"github.com/muesli/coral"
123)
124
125var (
126    rootCmd = &coral.Command{
127        Use:   "mango",
128        Short: "A man-page generator",
129    }
130)
131
132func main() {
133    manPage, err := mcoral.NewManPage(1, rootCmd)
134    if err != nil {
135        panic(err)
136    }
137
138    manPage = manPage.WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+
139        "Released under MIT license.")
140
141    fmt.Println(manPage.Build(roff.NewDocument()))
142}
143```
144
145## Feedback
146
147Got some feedback or suggestions? Please open an issue or drop me a note!
148
149* [Twitter](https://twitter.com/mueslix)
150* [The Fediverse](https://mastodon.social/@fribbledom)