Accept arguments which start with '-' if the next character is a digit
diff --git a/optstyle_other.go b/optstyle_other.go
index 29ca4b6..815db54 100644
--- a/optstyle_other.go
+++ b/optstyle_other.go
@@ -4,6 +4,7 @@
import (
"strings"
+ "unicode"
)
const (
@@ -17,7 +18,7 @@
}
func argumentIsOption(arg string) bool {
- if len(arg) > 1 && arg[0] == '-' && arg[1] != '-' {
+ if len(arg) > 1 && arg[0] == '-' && arg[1] != '-' && !unicode.IsDigit(rune(arg[1])) {
return true
}
diff --git a/parser_test.go b/parser_test.go
index 5792872..dff979a 100644
--- a/parser_test.go
+++ b/parser_test.go
@@ -14,6 +14,9 @@
Int int `long:"i"`
IntDefault int `long:"id" default:"1"`
+ Float64 float64 `long:"f"`
+ Float64Default float64 `long:"fd" default:"-3.14"`
+
String string `long:"str"`
StringDefault string `long:"strd" default:"abc"`
StringNotUnquoted string `long:"strnot" unquote:"false"`
@@ -41,6 +44,9 @@
Int: 0,
IntDefault: 1,
+ Float64: 0.0,
+ Float64Default: -3.14,
+
String: "",
StringDefault: "abc",
@@ -56,11 +62,14 @@
},
{
msg: "non-zero value arguments, expecting overwritten arguments",
- args: []string{"--i=3", "--id=3", "--str=def", "--strd=def", "--t=3ms", "--td=3ms", "--m=c:3", "--md=c:3", "--s=3", "--sd=3"},
+ args: []string{"--i=3", "--id=3", "--f=-2.71", "--fd=2.71", "--str=def", "--strd=def", "--t=3ms", "--td=3ms", "--m=c:3", "--md=c:3", "--s=3", "--sd=3"},
expected: defaultOptions{
Int: 3,
IntDefault: 3,
+ Float64: -2.71,
+ Float64Default: 2.71,
+
String: "def",
StringDefault: "def",
@@ -76,11 +85,14 @@
},
{
msg: "zero value arguments, expecting overwritten arguments",
- args: []string{"--i=0", "--id=0", "--str", "", "--strd=\"\"", "--t=0ms", "--td=0s", "--m=:0", "--md=:0", "--s=0", "--sd=0"},
+ args: []string{"--i=0", "--id=0", "--f=0", "--fd=0", "--str", "", "--strd=\"\"", "--t=0ms", "--td=0s", "--m=:0", "--md=:0", "--s=0", "--sd=0"},
expected: defaultOptions{
Int: 0,
IntDefault: 0,
+ Float64: 0,
+ Float64Default: 0,
+
String: "",
StringDefault: "",
@@ -345,6 +357,17 @@
args: []string{"--string-slice", "-"},
},
{
+ // Accept argumtns which start with '-' if the next character is a digit
+ args: []string{"--string-slice", "-3.14"},
+ },
+ {
+ // Do not accept argumtns which start with '-' if the next character is not a digit
+ args: []string{"--string-slice", "-character"},
+ expectError: true,
+ errType: ErrExpectedArgument,
+ errMsg: "expected argument for flag `--string-slice', but got option `-character'",
+ },
+ {
args: []string{"-o", "-", "-"},
rest: []string{"-", "-"},
},