Created
April 7, 2019 16:43
-
-
Save maxrp/c2384a73fb591a10da5366d62c2e064b to your computer and use it in GitHub Desktop.
A subtle(?) way to break option parsing in Pony (option vs. arg)
This file contains hidden or 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
--- main.pony Sun Apr 7 09:36:46 2019 | |
+++ main.pony.broken Sun Apr 7 09:37:31 2019 | |
@@ -25,5 +25,5 @@ | |
env.exitcode(1) | |
return | |
end | |
- let port: String = cmd.option("port").string() | |
+ let port: String = cmd.arg("port").string() | |
env.out.print("Port="+port) |
This file contains hidden or 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
use "cli" | |
actor Main | |
new create(env: Env) => | |
let cs = | |
try | |
CommandSpec.leaf("echo", "A sample echo program", [ | |
OptionSpec.string("port", "TCP port to listen on." | |
where short' = 'P', default' = "70") | |
])? .> add_help()? | |
else | |
env.exitcode(-1) // some kind of coding error | |
return | |
end | |
let cmd = | |
match CommandParser(cs).parse(env.args, env.vars) | |
| let c: Command => c | |
| let ch: CommandHelp => | |
ch.print_help(env.out) | |
env.exitcode(0) | |
return | |
| let se: SyntaxError => | |
env.out.print(se.string()) | |
env.exitcode(1) | |
return | |
end | |
let port: String = cmd.option("port").string() | |
env.out.print("Port="+port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment