Add example of HelpProvider + README
Relocate detailed help docs to main README
This commit is contained in:
committed by
Alec Thomas
parent
1db2ea27af
commit
6042c4b10e
@@ -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.
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user