-
-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial CLI package implementation w/ tests and updated examples (#1897)
- Loading branch information
Showing
14 changed files
with
1,727 additions
and
311 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use "cli" | ||
|
||
actor Main | ||
new create(env: Env) => | ||
try | ||
let cmd = | ||
match CommandParser(cli_spec()).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 | ||
|
||
// cmd is a valid Command, now use it. | ||
|
||
end | ||
|
||
fun tag cli_spec(): CommandSpec box ? => | ||
""" | ||
Builds and returns the spec for a sample chat client's CLI. | ||
""" | ||
let cs = CommandSpec.parent("chat", "A sample chat program", [ | ||
OptionSpec.bool("admin", "Chat as admin" where default' = false) | ||
OptionSpec.string("name", "Your name" where short' = 'n') | ||
OptionSpec.i64("volume", "Chat volume" where short' = 'v') | ||
], [ | ||
CommandSpec.leaf("say", "Say something", Array[OptionSpec](), [ | ||
ArgSpec.string("words", "The words to say") | ||
]) | ||
CommandSpec.leaf("emote", "Send an emotion", [ | ||
OptionSpec.f64("speed", "Emote play speed" where default' = F64(1.0)) | ||
], [ | ||
ArgSpec.string("emotion", "Emote to send") | ||
]) | ||
CommandSpec.parent("config", "Configuration commands", Array[OptionSpec](), [ | ||
CommandSpec.leaf("server", "Server configuration", Array[OptionSpec](), [ | ||
ArgSpec.string("address", "Address of the server") | ||
]) | ||
]) | ||
]) | ||
cs.add_help() | ||
cs |
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
Oops, something went wrong.