MustParse returns *Parser

This commit is contained in:
Alex Flint 2016-01-05 13:52:33 -08:00
parent d97f8fd931
commit 0c0f9a53ac
2 changed files with 4 additions and 2 deletions

View File

@ -26,7 +26,7 @@ type spec struct {
var ErrHelp = errors.New("help requested by user")
// MustParse processes command line arguments and exits upon failure
func MustParse(dest ...interface{}) {
func MustParse(dest ...interface{}) *Parser {
p, err := NewParser(dest...)
if err != nil {
fmt.Println(err)
@ -40,6 +40,7 @@ func MustParse(dest ...interface{}) {
if err != nil {
p.Fail(err.Error())
}
return p
}
// Parse processes command line arguments and stores them in dest

View File

@ -353,6 +353,7 @@ func TestMustParse(t *testing.T) {
Foo string
}
os.Args = []string{"example", "--foo", "bar"}
MustParse(&args)
parser := MustParse(&args)
assert.Equal(t, "bar", args.Foo)
assert.NotNil(t, parser)
}