aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Nigmatzianov <[email protected]>2017-04-27 14:51:45 +0200
committerAlbert Nigmatzianov <[email protected]>2017-04-27 14:51:45 +0200
commitf1d95a35e132e8a1868023a08932b14f0b8b8fcb (patch)
tree81d6fea2b4056860f24797b459355ffc1a6dd10a
parent314c91c3e94238576bab29cbcdd44b57ab8e0d39 (diff)
Unify error message for panic and f.out
-rw-r--r--flag.go14
1 files 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