arguments
import argumentssystem.args gives the words after the program’s name. arguments.read sorts them, so
tool --port 8080 --verbose photos does not need a loop of your own. Pass it system.args; the
example below uses a written list so that it can show its result.
import arguments
fn main { let given: List<String> := ["photos", "--port", "8080", "--verbose", "--name=Ada"] let a: arguments.Arguments := arguments.read(given) options(["port"]) print(a.words) print(a.flag("verbose")) print(a.option("port") else "80") print(a.option("name") else "nobody")}["photos"]true8080Adaoptions([…]) names the options that take a value. It is optional, because a value can always be
written --port=8080.
| Written | Read as |
|---|---|
--port 8080, -p 8080 | an option, if port or p is named in options([…]) |
--port=8080 | an option, always |
--verbose, -v | a flag |
-- | everything after it is a word, even if it starts with - |
| anything else | a word |
| Member | What it gives |
|---|---|
a.flag(name) -> Bool | whether this flag was written. |
a.option(name) -> String? | the value of this option, none if it was not written. |
a.int(name) -> Int? | the same as a whole number: a.int("port") else 80. none if the option is absent or not a whole number. |
a.float(name) -> Float? | the same as a Float. |
a.words -> List<String> | the other words, in order. |