Separate validation into a distinct step.

This allows help to be called even when the parse trace is invalid.
Without this, the command-line would have to be valid in order to use
help at all, which defeats the purpose.
This commit is contained in:
Alec Thomas
2018-05-29 16:42:53 +10:00
committed by Gerald Kaszuba
parent afbb431641
commit fdc7230e22
14 changed files with 569 additions and 225 deletions
+5 -3
View File
@@ -9,8 +9,10 @@ import (
)
var CLI struct {
Help bool `kong:"help='Display help.'"`
Rm struct {
Debug bool `kong:"help='Debug mode.'"`
Output string `kong:"help='File to output to.',placeholder='FILE'"`
Rm struct {
Force bool `kong:"help='Force removal.'"`
Recursive bool `kong:"help='Recursively remove files.'"`
@@ -23,7 +25,7 @@ var CLI struct {
}
func main() {
app := kong.Must(&CLI).Hook(&CLI.Help, kong.Help(nil, nil))
app := kong.Must(&CLI, kong.Description("A shell-like example app."))
cmd, err := app.Parse(os.Args[1:])
app.FatalIfErrorf(err)
s, _ := json.Marshal(&CLI)