fixed example comment, test coverage issue
This commit is contained in:
parent
d4cc703210
commit
51337ded77
|
@ -265,7 +265,7 @@ func (n *NameDotName) UnmarshalText(b []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// optional, implement in case you want to use defaults
|
||||
// optional: implement in case you want to display a default value in the usage string
|
||||
func (n *NameDotName) MarshalText() (text []byte, err error) {
|
||||
text = []byte(fmt.Sprintf("%s.%s", n.Head, n.Tail))
|
||||
return
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"strings"
|
||||
"fmt"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type NameDotName struct {
|
||||
|
@ -85,6 +86,42 @@ Options:
|
|||
assert.Equal(t, expectedHelp, help.String())
|
||||
}
|
||||
|
||||
type MyEnum int
|
||||
|
||||
func (n *MyEnum) UnmarshalText(b []byte) error {
|
||||
b = []byte("Hello")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *MyEnum) MarshalText() (text []byte, err error) {
|
||||
s := "There was a problem"
|
||||
text = []byte(s)
|
||||
err = errors.New(s)
|
||||
return
|
||||
}
|
||||
|
||||
func TestUsageError(t *testing.T) {
|
||||
expectedHelp := `Usage: example [--name NAME]
|
||||
|
||||
Options:
|
||||
--name NAME [default: error: There was a problem]
|
||||
--help, -h display this help and exit
|
||||
`
|
||||
var args struct {
|
||||
Name *MyEnum
|
||||
}
|
||||
v := MyEnum(42)
|
||||
args.Name = &v
|
||||
p, err := NewParser(Config{"example"}, &args)
|
||||
|
||||
// NB: some might might expect there to be an error here
|
||||
require.NoError(t, err)
|
||||
|
||||
var help bytes.Buffer
|
||||
p.WriteHelp(&help)
|
||||
assert.Equal(t, expectedHelp, help.String())
|
||||
}
|
||||
|
||||
func TestUsageLongPositionalWithHelp_legacyForm(t *testing.T) {
|
||||
expectedHelp := `Usage: example VERYLONGPOSITIONALWITHHELP
|
||||
|
||||
|
|
Loading…
Reference in New Issue