Draft
Format
command param1 -flag --explicit value --multiple v1 v2 v3
Parameters types
- flags: boolean value present/absent
- named arguments: arbitrary value, ex.
param1
- explicit arguments:
--name value with one or two dashes
- multivalued arguments:
--multi v1 v2 v3 ..., each value is separated by a space
Quotes
Values can be quoted to include spaces.
"single value"
'another value'
"you can use single 'quotes' in double-quoted strings and vice-versa"
Subsitution
Use $var or ${expr} or $(expr) in your command and it will be replaced by the corresponding value.
Escapements
\n: newline
\t: tab
\* where * is any other character: this character as-is, not interpreted by the parser
Example
warp [set|del] home [x,y,z[,world]] [--public]
Command definition
createCommand("warp", new ManagedCommand {
optArg("instruction")
arg("name")
optArg("location", LocationParser)
optFlag("public")
def execute(by: Actor, args: ArgsMap, unnamed: Seq[String]) = {
val name = args("name") // String
val location = args.get("location") // Option[Location]
val isPublic = args("public") // Boolean
val warp = findWarp(by, name)
args("instruction") match { // Option[String]
case None => by ! Teleport(warp.location)
case Some("set") => ...
case Some("del") => ...
}
})
Implementation notes
To handle an optional optArg preceding a required arg, the parser should count the number of parameters and fill the optional arguments, in the definition order, only if there are more arguments than required.
Draft
Format
command param1 -flag --explicit value --multiple v1 v2 v3Parameters types
param1--name valuewith one or two dashes--multi v1 v2 v3 ..., each value is separated by a spaceQuotes
Values can be quoted to include spaces.
Subsitution
Use
$varor${expr}or$(expr)in your command and it will be replaced by the corresponding value.Escapements
\n: newline\t: tab\*where*is any other character: this character as-is, not interpreted by the parserExample
warp [set|del] home [x,y,z[,world]] [--public]Command definition
Implementation notes
To handle an optional
optArgpreceding a requiredarg, the parser should count the number of parameters and fill the optional arguments, in the definition order, only if there are more arguments than required.