aboutsummaryrefslogtreecommitdiff
path: root/flag.go
diff options
context:
space:
mode:
authorfabianofranz <[email protected]>2015-04-22 14:20:17 -0300
committerfabianofranz <[email protected]>2015-04-22 14:20:17 -0300
commitf21662750abbd76e54f307765b0986b357ed8b92 (patch)
tree9f0593d2019fc515b03dcaff5e39110031d2a404 /flag.go
parent18d831e92d67eafd1b0db8af9ffddbd04f7ae1f4 (diff)
Add support to short form with equal sign: -p=value
Diffstat (limited to 'flag.go')
-rw-r--r--flag.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/flag.go b/flag.go
index 5dc5373..c43edad 100644
--- a/flag.go
+++ b/flag.go
@@ -141,12 +141,12 @@ type FlagSet struct {
// A Flag represents the state of a flag.
type Flag struct {
- Name string // name as it appears on command line
- Shorthand string // one-letter abbreviated flag
- Usage string // help message
- Value Value // value as set
- DefValue string // default value (as text); for usage message
- Changed bool // If the user set the value (or if left to default)
+ Name string // name as it appears on command line
+ Shorthand string // one-letter abbreviated flag
+ Usage string // help message
+ Value Value // value as set
+ DefValue string // default value (as text); for usage message
+ Changed bool // If the user set the value (or if left to default)
Annotations map[string][]string // used by cobra.Command bash autocomple code
}
@@ -507,7 +507,8 @@ func (f *FlagSet) parseShortArg(s string, args []string) (a []string, err error)
continue
}
if i < len(shorthands)-1 {
- if e := f.setFlag(flag, shorthands[i+1:], s); e != nil {
+ v := strings.TrimPrefix(shorthands[i+1:], "=")
+ if e := f.setFlag(flag, v, s); e != nil {
err = e
return
}
@@ -554,7 +555,7 @@ func (f *FlagSet) parseArgs(args []string) (err error) {
args, err = f.parseShortArg(s, args)
}
if err != nil {
- return
+ return
}
}
return