-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of HelpProvider + README
Relocate detailed help docs to main README
- Loading branch information
1 parent
1db2ea2
commit 6042c4b
Showing
3 changed files
with
159 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |