parent
4a13872104
commit
da2620a37f
33
README.md
33
README.md
|
@ -9,6 +9,39 @@ With `ffmd` you can generate markdown docs for both `flag.FlagSet` and `ffcli.Co
|
||||||
|
|
||||||
Check out [examples](examples) for some sample generated docs.
|
Check out [examples](examples) for some sample generated docs.
|
||||||
|
|
||||||
|
## Generate your docs
|
||||||
|
|
||||||
|
```go
|
||||||
|
//go:build generate
|
||||||
|
// +build generate
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.jolheiser.com/ffmd"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fi, err := os.Create("docs.md")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer fi.Close()
|
||||||
|
|
||||||
|
// cmd is the ffcli.Command
|
||||||
|
md, err := ffmd.Command(cmd)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := fi.WriteString(md); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ func main() {
|
||||||
fs.Duration("duration-flag", 0, "Duration flag with no default")
|
fs.Duration("duration-flag", 0, "Duration flag with no default")
|
||||||
fs.Duration("duration-flag-default", time.Minute*5, "Duration flag with default")
|
fs.Duration("duration-flag-default", time.Minute*5, "Duration flag with default")
|
||||||
|
|
||||||
md, err := ffmd.FromFlagSet(fs)
|
md, err := ffmd.FlagSet(fs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ func main() {
|
||||||
cmd2.Subcommands = []*ffcli.Command{cmd3, cmd5}
|
cmd2.Subcommands = []*ffcli.Command{cmd3, cmd5}
|
||||||
cmd3.Subcommands = []*ffcli.Command{cmd4}
|
cmd3.Subcommands = []*ffcli.Command{cmd4}
|
||||||
|
|
||||||
md, err := ffmd.FromCommand(cmd)
|
md, err := ffmd.Command(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ func main() {
|
||||||
Subcommands: nil,
|
Subcommands: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
md, err := ffmd.FromCommand(cmd)
|
md, err := ffmd.Command(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
8
ffmd.go
8
ffmd.go
|
@ -19,13 +19,13 @@ var (
|
||||||
Template = template.Must(template.New("").Parse(ffmdtmpl))
|
Template = template.Must(template.New("").Parse(ffmdtmpl))
|
||||||
)
|
)
|
||||||
|
|
||||||
// FromCommand turns a ffcli.Command into markdown
|
// Command turns a ffcli.Command into markdown
|
||||||
func FromCommand(cmd *ffcli.Command) (string, error) {
|
func Command(cmd *ffcli.Command) (string, error) {
|
||||||
return fromCommand(cmd, 1)
|
return fromCommand(cmd, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromFlagSet turns a flag.FlagSet into markdown
|
// FlagSet turns a flag.FlagSet into markdown
|
||||||
func FromFlagSet(fs *flag.FlagSet) (string, error) {
|
func FlagSet(fs *flag.FlagSet) (string, error) {
|
||||||
return flagSetCommand(fs, 2).Markdown()
|
return flagSetCommand(fs, 2).Markdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue