Skip to content

Commit

Permalink
add the method MustOpt for OptGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Jun 13, 2019
1 parent 7281031 commit f38f75e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ func (g *OptGroup) Opt(name string) (opt Opt, exist bool) {
return
}

// MustOpt is the same as Opt(name), but panic if the option does not exist.
func (g *OptGroup) MustOpt(name string) Opt {
if opt, ok := g.Opt(name); ok {
return opt
}
panic(NewOptError(g.name, name, ErrNoOpt, nil))
}

// HasOpt reports whether there is an option named name in the current group.
func (g *OptGroup) HasOpt(name string) bool {
g.lock.RLock()
Expand Down

0 comments on commit f38f75e

Please sign in to comment.