From f1d95a35e132e8a1868023a08932b14f0b8b8fcb Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Thu, 27 Apr 2017 14:51:45 +0200 Subject: Unify error message for panic and f.out --- flag.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/flag.go b/flag.go index 72bed82..f9984fb 100644 --- a/flag.go +++ b/flag.go @@ -787,23 +787,25 @@ func (f *FlagSet) AddFlag(flag *Flag) { return } if len(flag.Shorthand) > 1 { - fmt.Fprintf(f.out(), "%s shorthand more than ASCII character: %s\n", f.name, flag.Shorthand) - panic("shorthand is more than one character") + msg := fmt.Sprintf("%q shorthand is more than one ASCII character", flag.Shorthand) + fmt.Fprintf(f.out(), msg) + panic(msg) } if f.shorthands == nil { f.shorthands = make(map[byte]*Flag) } c := flag.Shorthand[0] - old, alreadyThere := f.shorthands[c] + used, alreadyThere := f.shorthands[c] if alreadyThere { - fmt.Fprintf(f.out(), "%s shorthand reused: %q for %s already used for %s\n", f.name, c, flag.Name, old.Name) - panic(fmt.Sprintf("unable to redefine %q shorthand", c)) + msg := fmt.Sprintf("unable to redefine %q shorthand in %q flagset: it's already used for %q flag", c, f.name, used.Name) + fmt.Fprintf(f.out(), msg) + panic(msg) } f.shorthands[c] = flag } // AddFlagSet adds one FlagSet to another. If a flag is already present in f -// the flag from newSet will be ignored +// the flag from newSet will be ignored. func (f *FlagSet) AddFlagSet(newSet *FlagSet) { if newSet == nil { return -- cgit v1.2.3