Help!
This commit is contained in:
committed by
Gerald Kaszuba
parent
48af58cefa
commit
2afd4ba47b
+38
-5
@@ -2,7 +2,6 @@ package kong
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -10,11 +9,16 @@ import (
|
||||
|
||||
func TestHelp(t *testing.T) {
|
||||
var cli struct {
|
||||
String string `kong:"help='A string flag.'"`
|
||||
Bool bool `kong:"help='A bool flag.'"`
|
||||
String string `help:"A string flag."`
|
||||
Bool bool `help:"A bool flag with very long help that wraps a lot and is verbose and is really verbose."`
|
||||
|
||||
One struct {
|
||||
} `kong:"cmd"`
|
||||
Flag string `help:"Nested flag."`
|
||||
} `cmd help:"A subcommand."`
|
||||
|
||||
Two struct {
|
||||
Flag string `help:"Nested flag under two."`
|
||||
} `cmd help:"Another subcommand."`
|
||||
}
|
||||
w := bytes.NewBuffer(nil)
|
||||
exited := false
|
||||
@@ -27,5 +31,34 @@ func TestHelp(t *testing.T) {
|
||||
_, err := app.Parse([]string{"--help"})
|
||||
require.NoError(t, err)
|
||||
require.True(t, exited)
|
||||
fmt.Println(w.String())
|
||||
require.Equal(t, `usage: test-app [<flags>]
|
||||
|
||||
A test app.
|
||||
|
||||
Flags:
|
||||
--help Show context-sensitive help.
|
||||
--string=STRING A string flag.
|
||||
--bool A bool flag with very long help that wraps a lot and is
|
||||
verbose and is really verbose.
|
||||
|
||||
Commands:
|
||||
one [<flags>]
|
||||
A subcommand.
|
||||
|
||||
two [<flags>]
|
||||
Another subcommand.
|
||||
`, w.String())
|
||||
|
||||
exited = false
|
||||
w.Truncate(0)
|
||||
_, err = app.Parse([]string{"one", "--help"})
|
||||
require.NoError(t, err)
|
||||
require.True(t, exited)
|
||||
require.Equal(t, `usage: test-app one [<flags>]
|
||||
|
||||
A subcommand.
|
||||
|
||||
Flags:
|
||||
--flag=STRING Nested flag.
|
||||
`, w.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user