-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #97 Relatively straightforward change. We do `head.split("=", 2) match` to see if it contains any `=`, and if so treat the portion of the string after the first `=` as the value. Added some unit test to cover both success cases and failure cases: use with short names or with flags is unsupported.
- Loading branch information
Showing
2 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package mainargs | ||
import utest._ | ||
|
||
object EqualsSyntaxTests extends TestSuite { | ||
|
||
object Main { | ||
@main | ||
def run( | ||
@arg(short = 'f', doc = "String to print repeatedly") | ||
foo: String, | ||
@arg(name = "my-num", doc = "How many times to print string") | ||
myNum: Int = 2, | ||
@arg(doc = "Example flag") | ||
bool: Flag | ||
) = { | ||
foo * myNum + " " + bool.value | ||
} | ||
} | ||
|
||
val tests = Tests { | ||
test("simple") { | ||
ParserForMethods(Main).runOrThrow(Array("--foo=bar", "--my-num=3")) ==> | ||
"barbarbar false" | ||
} | ||
test("multipleEquals") { | ||
// --foo=bar syntax still works when there's an `=` on the right | ||
ParserForMethods(Main).runOrThrow(Array("--foo=bar=qux")) ==> | ||
"bar=quxbar=qux false" | ||
} | ||
test("shortName") { | ||
// -f=bar syntax doesn't work for short names | ||
ParserForMethods(Main).runEither(Array("-f=bar")) ==> | ||
Left( | ||
"""Missing argument: -f --foo <str> | ||
|Unknown argument: "-f=bar" | ||
|Expected Signature: run | ||
| -f --foo <str> String to print repeatedly | ||
| --my-num <int> How many times to print string | ||
| --bool Example flag | ||
| | ||
|""".stripMargin) | ||
} | ||
test("notFlags") { | ||
// -f=bar syntax doesn't work for flags | ||
ParserForMethods(Main).runEither(Array("--foo=bar", "--bool=true")) ==> | ||
Left("""Unknown argument: "--bool=true" | ||
|Expected Signature: run | ||
| -f --foo <str> String to print repeatedly | ||
| --my-num <int> How many times to print string | ||
| --bool Example flag | ||
| | ||
|""".stripMargin) | ||
} | ||
} | ||
} |