Skip to content

Commit

Permalink
Merge pull request #28 from clagraff/bugfix-missing-return
Browse files Browse the repository at this point in the history
fixed bad conditionals and missing returns
  • Loading branch information
clagraff authored Nov 7, 2016
2 parents 1ee7ce1 + 849d92a commit b0355c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Upcoming
## Bug Fixes
- Added missing return after executing callback for options.
- Fixed conditions where the callback is not called if an error occurred.
19 changes: 10 additions & 9 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func (p *Parser) Parse(allArgs ...string) {

if usedParser != true {
p.Callback(p, p.Namespace, nil, MissingParserErr{p.Parsers})
return
}
}

Expand All @@ -326,12 +327,12 @@ func (p *Parser) Parse(allArgs ...string) {

if option == nil {
p.Callback(p, p.Namespace, args, InvalidOptionErr{optionName})
return
}

args, err = option.DesiredAction(p, option, args...)
if err != nil {
p.Callback(p, p.Namespace, args, err)
}
p.Callback(p, p.Namespace, args, err)
return
}

if len(args) > 0 {
Expand All @@ -340,9 +341,8 @@ func (p *Parser) Parse(allArgs ...string) {
delete(requiredOptions, opt.DisplayName())
}
_, err := opt.DesiredAction(p, opt, args...)
if err != nil {
p.Callback(p, p.Namespace, args, err)
}
p.Callback(p, p.Namespace, args, err)
return
}
}

Expand All @@ -354,17 +354,18 @@ func (p *Parser) Parse(allArgs ...string) {
delete(requiredOptions, f.DestName)
}
args, err = f.DesiredAction(p, f, args...)
if err != nil {
p.Callback(p, p.Namespace, args, err)
}
p.Callback(p, p.Namespace, args, err)
return
}

if len(requiredOptions) != 0 {
for _, option := range requiredOptions {
p.Callback(p, p.Namespace, args, MissingOptionErr{option.DisplayName()})
return
}
}
p.Callback(p, p.Namespace, args, nil)
return
}

// Path will set the parser's program name to the program name specified by the
Expand Down

0 comments on commit b0355c7

Please sign in to comment.