aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flag.go3
-rw-r--r--flag_test.go11
2 files changed, 10 insertions, 4 deletions
diff --git a/flag.go b/flag.go
index 5f14635..7fb0990 100644
--- a/flag.go
+++ b/flag.go
@@ -527,7 +527,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
}
diff --git a/flag_test.go b/flag_test.go
index ca500dd..c4055ed 100644
--- a/flag_test.go
+++ b/flag_test.go
@@ -185,7 +185,8 @@ func TestShorthand(t *testing.T) {
boolaFlag := f.BoolP("boola", "a", false, "bool value")
boolbFlag := f.BoolP("boolb", "b", false, "bool2 value")
boolcFlag := f.BoolP("boolc", "c", false, "bool3 value")
- stringFlag := f.StringP("string", "s", "0", "string value")
+ stringaFlag := f.StringP("stringa", "s", "0", "string value")
+ stringzFlag := f.StringP("stringz", "z", "0", "string value")
extra := "interspersed-argument"
notaflag := "--i-look-like-a-flag"
args := []string{
@@ -193,6 +194,7 @@ func TestShorthand(t *testing.T) {
extra,
"-cs",
"hello",
+ "-z=something",
"--",
notaflag,
}
@@ -212,8 +214,11 @@ func TestShorthand(t *testing.T) {
if *boolcFlag != true {
t.Error("boolc flag should be true, is ", *boolcFlag)
}
- if *stringFlag != "hello" {
- t.Error("string flag should be `hello`, is ", *stringFlag)
+ if *stringaFlag != "hello" {
+ t.Error("stringa flag should be `hello`, is ", *stringaFlag)
+ }
+ if *stringzFlag != "something" {
+ t.Error("stringz flag should be `something`, is ", *stringzFlag)
}
if len(f.Args()) != 2 {
t.Error("expected one argument, got", len(f.Args()))