-
Notifications
You must be signed in to change notification settings - Fork 13
Argument syntax
Typin supports an argument syntax which is based on the POSIX standard. To be fair, nobody really knows what the standard is about and very few tools actually follow it to the letter, so for the purpose of having dashes and spaces, Typin is using the "standard command line syntax".
More specifically, the following examples are all valid:
-
myapp --foo bar
sets option"foo"
to value"bar"
-
myapp -f bar
sets option'f'
to value"bar"
-
myapp --switch
sets option"switch"
without value -
myapp -s
sets option's'
without value -
myapp -abc
sets options'a'
,'b'
and'c'
without value -
myapp -xqf bar
sets options'x'
and'q'
without value, and option'f'
to value"bar"
-
myapp -i file1.txt file2.txt
sets option'i'
to a sequence of values"file1.txt"
and"file2.txt"
-
myapp -i file1.txt -i file2.txt
sets option'i'
to a sequence of values"file1.txt"
and"file2.txt"
-
myapp cmd abc -o
routes to commandcmd
(assuming it exists) with parameterabc
and sets option'o'
without value
Argument parsing in Typin aims to be as deterministic as possible, ideally yielding the same result no matter the context. The only context-sensitive part in the parser is the command name resolution which needs to know what commands are available in order to discern between arguments that correspond to the command name and arguments which are parameters.
Options are always parsed the same way, disregarding the arity of the actual property it binds to. This means that myapp -i file1.txt file2.txt
will always be parsed as an option with multiple values, even if the underlying bound property is not enumerable. For the same reason, unseparated arguments such as myapp -ofile
will be treated as five distinct options 'o'
, 'f'
, 'i'
, 'l'
, 'e'
, instead of 'o'
being set to "file"
.
Because of these rules, order of arguments is semantically important and it always goes like this:
{directives} {command name} {parameters} {options}
The above design makes the usage of your applications a lot more intuitive and predictable, providing a better end-user experience.
Getting started
Advanced features
- Reporting errors
- Exception handling
- Metadata and startup message
- Graceful cancellation
- Dependency injection
- Middleware pipeline
- Environment variables
Utilities
Tests
Misc