diff options
| author | Albert Nigmatzianov <[email protected]> | 2017-04-27 14:51:45 +0200 |
|---|---|---|
| committer | Albert Nigmatzianov <[email protected]> | 2017-04-27 14:51:45 +0200 |
| commit | f1d95a35e132e8a1868023a08932b14f0b8b8fcb (patch) | |
| tree | 81d6fea2b4056860f24797b459355ffc1a6dd10a | |
| parent | 314c91c3e94238576bab29cbcdd44b57ab8e0d39 (diff) | |
Unify error message for panic and f.out
| -rw-r--r-- | flag.go | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -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 |
