aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Paris <[email protected]>2015-05-27 15:43:43 -0500
committerEric Paris <[email protected]>2015-05-27 15:43:43 -0500
commit8a0b846eb11d294deee8f68f697d48ac62aa372f (patch)
treedbb175e237ba809ef8fb2701659ec445daf4bb49
parentb91b2a94780f4e6b4d3b0c12fd9b5f4b05b1aa45 (diff)
parentcfd553f19144450e5fef25080aa469285ff96b88 (diff)
Merge pull request #24 from eparis/longArgCleanup
Slight code cleanup parsing long flags
-rw-r--r--flag.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/flag.go b/flag.go
index 9f16733..0070b93 100644
--- a/flag.go
+++ b/flag.go
@@ -529,14 +529,16 @@ func (f *FlagSet) parseLongArg(s string, args []string) (a []string, err error)
return
}
var value string
- if len(split) == 1 {
- if bv, ok := flag.Value.(boolFlag); !ok || !bv.IsBoolFlag() {
- err = f.failf("flag needs an argument: %s", s)
- return
- }
+ if len(split) == 2 {
+ // '--flag=arg'
+ value = split[1]
+ } else if bv, ok := flag.Value.(boolFlag); ok && bv.IsBoolFlag() {
+ // '--flag' (where flag is a bool)
value = "true"
} else {
- value = split[1]
+ // '--flag' (where flag was not a bool)
+ err = f.failf("flag needs an argument: %s", s)
+ return
}
err = f.setFlag(flag, value, s)
return