Browse Source

MustParse returns *Parser

Alex Flint 10 years ago
parent
commit
0c0f9a53ac
2 changed files with 4 additions and 2 deletions
  1. +2
    -1
      parse.go
  2. +2
    -1
      parse_test.go

+ 2
- 1
parse.go 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


+ 2
- 1
parse_test.go 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)
}

Loading…
Cancel
Save