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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
# mango
[](https://github.com/muesli/mango/releases)
[](/LICENSE)
[](https://github.com/muesli/mango/actions)
[](https://goreportcard.com/report/muesli/mango)
[](https://pkg.go.dev/github.com/muesli/mango)
mango is a man-page generator for the Go flag, pflag, cobra, coral, and kong
packages. It extracts commands, flags, and arguments from your program and
enables it to self-document.
## Adapters
Currently the following adapters exist:
- flag: support for Go's standard flag package
- [mango-cobra](https://github.com/muesli/mango-cobra): an adapter for [cobra](https://github.com/spf13/cobra)
- [mango-coral](https://github.com/muesli/mango-coral): an adapter for [coral](https://github.com/muesli/coral)
- [mango-kong](https://github.com/alecthomas/mango-kong): an adapter for [kong](https://github.com/alecthomas/kong)
- [mango-pflag](https://github.com/muesli/mango-pflag): an adapter for the [pflag](https://github.com/spf13/pflag) package
## Usage with flag:
```go
import (
"flag"
"fmt"
"github.com/muesli/mango"
"github.com/muesli/mango/mflag"
"github.com/muesli/roff"
)
var (
one = flag.String("one", "", "first value")
two = flag.String("two", "", "second value")
)
func main() {
flag.Parse()
manPage := mango.NewManPage(1, "mango", "a man-page generator").
WithLongDescription("mango is a man-page generator for Go.\n"+
"Features:\n"+
"* User-friendly\n"+
"* Plugable").
WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+
"Released under MIT license.")
flag.VisitAll(mflag.FlagVisitor(manPage))
fmt.Println(manPage.Build(roff.NewDocument()))
}
```
Mango will extract all the flags from your app and generate a man-page similar
to this example:

## Usage with pflag:
```go
import (
"fmt"
"github.com/muesli/mango"
mpflag "github.com/muesli/mango-pflag"
"github.com/muesli/roff"
flag "github.com/spf13/pflag"
)
func main() {
flag.Parse()
manPage := mango.NewManPage(1, "mango", "a man-page generator").
WithLongDescription("mango is a man-page generator for Go.").
WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+
"Released under MIT license.")
flag.VisitAll(mpflag.PFlagVisitor(manPage))
fmt.Println(manPage.Build(roff.NewDocument()))
}
```
## Usage with cobra:
```go
import (
"fmt"
mcobra "github.com/muesli/mango-cobra"
"github.com/muesli/roff"
"github.com/spf13/cobra"
)
var (
rootCmd = &cobra.Command{
Use: "mango",
Short: "A man-page generator",
}
)
func main() {
manPage, err := mcobra.NewManPage(1, rootCmd)
if err != nil {
panic(err)
}
manPage = manPage.WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+
"Released under MIT license.")
fmt.Println(manPage.Build(roff.NewDocument()))
}
```
## Usage with coral:
```go
import (
"fmt"
mcoral "github.com/muesli/mango-coral"
"github.com/muesli/roff"
"github.com/muesli/coral"
)
var (
rootCmd = &coral.Command{
Use: "mango",
Short: "A man-page generator",
}
)
func main() {
manPage, err := mcoral.NewManPage(1, rootCmd)
if err != nil {
panic(err)
}
manPage = manPage.WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+
"Released under MIT license.")
fmt.Println(manPage.Build(roff.NewDocument()))
}
```
## Feedback
Got some feedback or suggestions? Please open an issue or drop me a note!
* [Twitter](https://twitter.com/mueslix)
* [The Fediverse](https://mastodon.social/@fribbledom)
|