From f38f75e6f456d79fb9a60c38ab807463d4db35c3 Mon Sep 17 00:00:00 2001 From: xgfone Date: Thu, 13 Jun 2019 09:35:53 +0800 Subject: [PATCH] add the method MustOpt for OptGroup --- group.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/group.go b/group.go index 9291eda..1fc8e5c 100644 --- a/group.go +++ b/group.go @@ -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()