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:
committed by
Gerald Kaszuba
parent
afbb431641
commit
fdc7230e22
@@ -0,0 +1,31 @@
|
||||
package kong
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHelp(t *testing.T) {
|
||||
var cli struct {
|
||||
String string `kong:"help='A string flag.'"`
|
||||
Bool bool `kong:"help='A bool flag.'"`
|
||||
|
||||
One struct {
|
||||
} `kong:"cmd"`
|
||||
}
|
||||
w := bytes.NewBuffer(nil)
|
||||
exited := false
|
||||
app := mustNew(t, &cli,
|
||||
Name("test-app"),
|
||||
Description("A test app."),
|
||||
Writers(w, w),
|
||||
ExitFunction(func(int) { exited = true }),
|
||||
)
|
||||
_, err := app.Parse([]string{"--help"})
|
||||
require.NoError(t, err)
|
||||
require.True(t, exited)
|
||||
fmt.Println(w.String())
|
||||
}
|
||||
Reference in New Issue
Block a user