diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-10-18 18:15:21 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-10-18 18:15:21 -0400 |
| commit | f77bcd8f5777824064088f03b06a1fc9bc2da8b0 (patch) | |
| tree | 5c2176e65bf4deb619bbf647a58ab10510c2ae5d /docs/command-line-parsing.md | |
| parent | 6723cba7aba6cabb99058e58b6c8af4d5ec7c1d7 (diff) | |
Update docs
Diffstat (limited to 'docs/command-line-parsing.md')
| -rw-r--r-- | docs/command-line-parsing.md | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/docs/command-line-parsing.md b/docs/command-line-parsing.md index 7acfe95c..283c41d0 100644 --- a/docs/command-line-parsing.md +++ b/docs/command-line-parsing.md @@ -21,10 +21,10 @@ Compiled executable: greet $ ./greet greet: Required argument 'name' was not provided! -Signature: greet [--help] <name> [--be-excited|-E|--no-be-exited] +Usage: greet [--help] <name> [--be-excited|-E|--no-be-exited] $ ./greet --help -Signature: greet [--help] <name> [--be-excited|-E|--no-be-excited] +Usage: greet [--help] <name> [--be-excited|-E|--no-be-excited] $ ./greet "Zaphod" Hi Zaphod. @@ -40,7 +40,7 @@ Hi Zaphod. $ ./greet --not-a-real-argument "Bob" greet: Unrecognized argument: --not-a-real-argument -Signature: greet [--help] <name> [--be-excited|-E|--no-be-excited] +Usage: greet [--help] <name> [--be-excited|-E|--no-be-excited] ``` Underscores in argument names are converted to dashes when parsing command line @@ -91,27 +91,50 @@ or `1.23`) or scientific notation (`1e99`). For fixed-size integers (`Int64`, `Int32`, `Int16`, `Int8`), arguments that exceed the representable range for those values are considered usage errors. +### Structs + +For structs, values can be passed using positional arguments for each struct +field. + +``` +# foo.tm +struct Pair(x,y:Int) + +func main(pair:Pair) + >> pair + + +$ tomo foo.tm -- --pair 1 2 +Pair(x=1, y=2) +``` + +Tomo does not currently support omitting fields with default values or passing +individual struct fields by named flag. + ### Enums -For enums that do not have member values (e.g. `enum Foo(Baz, Qux)`, not `enum -Foo(Baz(x:Int), Qux)`, Tomo supports automatic command line argument parsing. -Parsing is case-insensitive: +For enums, values can be passed using the enum's tag name and each of its +fields positionally (the same as for structs). Parsing is case-sensitive: ``` # foo.tm -enum Foo(One, Two, Three) +enum Foo(Nothing, AnInteger(i:Int), TwoThings(i:Int, text:Text)) func main(foo:Foo) >> foo -# Signature: -$ tomo foo.tm one ->> Foo.One +$ tomo foo.tm -- Nothing +Nothing + +$ tomo foo.tm -- AnInteger 123 +AnInteger(123) -$ tomo foo.tm xxx -foo: Invalid value provided for --foo; valid values are: One Two -Signature: foo [--help] <foo> +$ tomo foo.tm -- TwoThings 123 hello +TwoThings(i=123, text="hello") ``` +Like structs, enums do not currently support passing fields as flags or +omitting fields with default values. + ### Lists of Text Currently, Tomo supports accepting arguments that take a list of text. |
