Add example of HelpProvider + README

Relocate detailed help docs to main README
This commit is contained in:
Keilin Olsen
2021-11-30 23:18:58 +11:00
committed by Alec Thomas
parent 1db2ea27af
commit 6042c4b10e
3 changed files with 159 additions and 43 deletions
+3
View File
@@ -0,0 +1,3 @@
# Example of custom help providers
This example demonstrates how to add `Help() string` functions (ie. the `HelpProvider` interface) to your commands, arguments, and flags to augment the help text provided using `help:""` style tagged annotations.
+49
View File
@@ -0,0 +1,49 @@
package main
import (
"fmt"
"github.com/alecthomas/kong"
)
var cli struct {
Flag flagWithHelp `help:"Regular flag help"`
Echo commandWithHelp `cmd:"" help:"Regular command help"`
}
type flagWithHelp bool
func (f *flagWithHelp) Help() string {
return "🏁 additional flag help"
}
type commandWithHelp struct {
Msg argumentWithHelp `arg:"" help:"Regular argument help"`
}
func (c *commandWithHelp) Help() string {
return "🚀 additional command help"
}
type argumentWithHelp struct {
Msg string `arg:""`
}
func (f *argumentWithHelp) Help() string {
return "📣 additional argument help"
}
func main() {
ctx := kong.Parse(&cli,
kong.Name("help"),
kong.Description("An app demonstrating HelpProviders"),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
Summary: false,
}))
switch ctx.Command() {
case "echo <msg>":
fmt.Println(cli.Echo.Msg)
}
}