You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jolheiser 763d358701
Mention aliases
1 month ago
examples Mention aliases 1 month ago
.gitignore Initial commit 11 months ago
LICENSE Initial commit 11 months ago
README.md Mention aliases 1 month ago
ffmd.go Add alias support 1 month ago
ffmd.tmpl Add alias support 1 month ago
go.mod Initial commit 11 months ago
go.sum Initial commit 11 months ago
tree.go Split examples and fix tree 11 months ago
tree_test.go Initial commit 11 months ago

README.md

ffmd

Go Reference

One of the things that I really liked about urfave/cli was that it could generate markdown docs for my commands.

With ffmd you can generate markdown docs for both flag.FlagSet and ffcli.Command (with any amount of sub-commands).

Check out examples for some sample generated docs.

Generate your docs

//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)
    }
}

Aliases

While the stdlib doesn't directly support flag aliases, this library allows for neater generation using a special syntax.

package main

import "flag"

func main() {
	fs := flag.NewFlagSet("myapp", flag.ExitOnError)
	stringFlag := fs.String("string", "", "String flag")
	fs.StringVar(stringFlag, "s", *stringFlag, "--string")
}

In the above code, a second flag was registered with the special Usage that simply declared what the long-form flag name was.
In this scenario, ffmd will generate docs similar to

--string,-s

See the example.

License

MIT