Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
Merge branch 'fix/94' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Schlitter committed Feb 19, 2018
2 parents af8ad85 + 65d19af commit 23cb731
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 19 deletions.
12 changes: 0 additions & 12 deletions src/Neodoc/ArgParser/Argument.purs
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,6 @@ longOption term n mArg = do
, explicitArg: false
}

-- case 3:
-- The name is a substring of the input and no explicit argument has been
-- provdided.
go (LOpt n' Nothing) _ | not isFlag
= case stripPrefix (Pattern n) n' of
Just s ->
pure { rawValue: Just s
, hasConsumedArg: false
, explicitArg: false
}
_ -> fail "Invalid substring"

go a _ = fail $ "Invalid token: " <> pretty a

shortOption
Expand Down
4 changes: 2 additions & 2 deletions test/Test/Spec/ArgParserSpec.purs
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,10 @@ argParserSpec = \_ -> describe "The parser generator" do
(Just (defaultOptions { stopAt = [ "--foo" ] }))
[ "--foo=BAR", "-f"]
[ "--foo" :> V.array [ V.str "BAR", V.str "-f" ] ]
, pass
, fail
(Just (defaultOptions { stopAt = [ "--foo" ] }))
[ "--fooBAR", "-f"]
[ "--foo" :> V.array [ V.str "BAR", V.str "-f" ] ]
"unknown option --fooBAR"
]
))
])
Expand Down
77 changes: 72 additions & 5 deletions testcases.docopt
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ $ prog --foo --foo=bar
{"--foo": [true, "bar"]}

$ prog --foo --foobar
{"--foo": [true, "bar"]}
"unknown option --foobar" # See #94

$ prog --foo --foo bar
{"--foo": [true, "bar"]}
Expand Down Expand Up @@ -2674,13 +2674,13 @@ Options: -f, --foo=FOO
"""

$ prog --foobar
{"-f": "bar", "--foo": "bar"}
"unknown option --foobar" # See #94

$ prog --foo=bar
{"-f": "bar", "--foo": "bar"}

$ prog --foobar QUX
"unknown command QUX"
"unknown option --foobar" # See #94

$ prog --foo=bar QUX
"unknown command QUX"
Expand All @@ -2691,13 +2691,13 @@ Options: -f, --foo[=FOO]
"""

$ prog --foobar
{"-f": "bar", "--foo": "bar"}
"unknown option --foobar" # See #94

$ prog --foo=bar
{"-f": "bar", "--foo": "bar"}

$ prog --foobar QUX
"unknown command QUX"
"unknown option --foobar" # See #94

$ prog --foo=bar QUX
"unknown command QUX"
Expand Down Expand Up @@ -3646,3 +3646,70 @@ $ prog -d -c -a -b

$ prog -a -b -c -d
{"-a": true, "-b": true, "-c": true, "-d": true}

# Issue #94

r"""
Usage:
test [--foo <bar>] [--foo-bar <baz>]
"""

$ prog/s --foo 123
{"--foo": 123}

$ prog/s --foo-bar 456
{"--foo-bar": 456}

$ prog/s --foo-bar
"option requires argument: --foo-bar"

$ prog/s --foo
"option requires argument: --foo"

$ prog/s --foo --foo-bar
"option requires argument: --foo"

$ prog/s --foo-bar --foo
"option requires argument: --foo-bar"

$ prog/s --foo-bar=--foo
{"--foo-bar": "--foo"}

$ prog/s --foo=--foo-bar
{"--foo": "--foo-bar"}

r"""
Usage:
test [--foo <bar>]
test [--foo-bar <baz>]
"""

$ prog/s --foo 123
{"--foo": 123}

$ prog/s --foo-bar 456
{"--foo-bar": 456}

$ prog/s --foo-bar
"option requires argument: --foo-bar"

$ prog/s --foo
"option requires argument: --foo"

$ prog/s --foo --foo-bar
"option requires argument: --foo"

$ prog/s --foo-bar --foo
"option requires argument: --foo-bar"

$ prog/s --foo-bar=--foo
{"--foo-bar": "--foo"}

$ prog/s --foo=--foo-bar
{"--foo": "--foo-bar"}

$ prog/s --foo=--foo-bar --foo-bar
"unexpected option --foo-bar"

$ prog/s --foo-bar=--foo --foo
"unexpected option --foo"

0 comments on commit 23cb731

Please sign in to comment.