Command line argument parsing.
| Optparse.hx | Command line argument parsing. |
| ReaderResult | Result of some reader function. |
| Variables | |
| value | The value read by a reader function. |
| advance | How many parameters has been parsed by the reader function. |
| Types | |
| Types | |
| OptionReader | Prototype of a reader function. |
| OptionWriter | Prototype of a writer function. |
| OptparseException | Exception class thrown by Optparse |
| Functions | |
| new | Constructor |
| toString | Converts the exception to a string. |
| Optparse | Command line argument parsing class. |
| new | Constructor. |
| addOption | Adds a new command line option to the parser. |
| parse | Parses the command line arguments according to the previously specified options by addOption. |
| getHelp | Generates option usage help from the previously specified help and help_arg paramteres in addOption. |
| Reader functions | |
| readerNull | Null option reader. |
| readerString | String option reader. |
| readerInt | Integer option reader. |
| readerFloat | Float option reader. |
| readerKVArray | Key/value pair list option reader. |
| Writer functions | |
| writerNull | Null option writer. |
| writerStore | Store option writer. |
| writerStoreTrue | True boolean value option writer. |
| writerStoreFalse | False boolean value option writer. |
| writerIncrement | Increment option writer. |
| writerAppend | Array append option writer. |
| makeWriterStoreConst | Constant option writer creator. |
| Types | |
| OptionReader | Prototype of a reader function. |
| OptionWriter | Prototype of a writer function. |
Command line argument parsing class.
| new | Constructor. |
| addOption | Adds a new command line option to the parser. |
| parse | Parses the command line arguments according to the previously specified options by addOption. |
| getHelp | Generates option usage help from the previously specified help and help_arg paramteres in addOption. |
| Reader functions | |
| readerNull | Null option reader. |
| readerString | String option reader. |
| readerInt | Integer option reader. |
| readerFloat | Float option reader. |
| readerKVArray | Key/value pair list option reader. |
| Writer functions | |
| writerNull | Null option writer. |
| writerStore | Store option writer. |
| writerStoreTrue | True boolean value option writer. |
| writerStoreFalse | False boolean value option writer. |
| writerIncrement | Increment option writer. |
| writerAppend | Array append option writer. |
| makeWriterStoreConst | Constant option writer creator. |
public function addOption( short: String, long: String, field: String, reader: OptionReader, writer: OptionWriter, ?help: String, ?help_arg: String )
Adds a new command line option to the parser.
| short | the short version of the command line option. Can be null if no short version is required. (Example: “-h”) |
| long | the long version of the command line option. Can be null if no long version is required. (Example: “--help”) |
| field | the name of the field which will hold the parsed argument value |
| reader | the option reader function which will parse the command line option and it’s arguments (if there are any) |
| writer | the option writer function which will store the value parsed by the reader (or any other value if necessary) |
| help | the help text for the option. It will be included in the help message generated by getHelp. Can be omitted. |
| help_arg | the format description for the argument(s) of the command line option. Can be omitted. |
public function parse( options: Dynamic, args: Array<String>, start: Int = 0 ): Int
Parses the command line arguments according to the previously specified options by addOption.
| options | the object holding all the option fields |
| args | the array of command line arguments |
| start | the start index of parsing |
The index of the command line argument which cannot be parsed.
public function getHelp(): StringBuf
Generates option usage help from the previously specified help and help_arg paramteres in addOption.
The generated help as a String.
public static function readerInt( args: Array<String>, act: Int ): ReaderResult
Integer option reader. Used for options with exactly one integer argument.
| args | the array of command line arguments |
| act | the index of actually parsed argument |
| value | the argument as an Int |
| advance | 2 |
OptparseException if the argument is missing or cannot be converted to Int.
public static function readerFloat( args: Array<String>, act: Int ): ReaderResult
Float option reader. Used for options with exactly one floating point argument.
| args | the array of command line arguments |
| act | the index of actually parsed argument |
| value | the argument as a Float |
| advance | 2 |
OptparseException if the argument is missing or cannot be converted to Float.
public static function readerKVArray( args: Array<String>, act: Int ): ReaderResult
Key/value pair list option reader. Used for options with a list of key/value pairs argument. The key/value pairs are in the following format:
key[=value][:key[=value]...]
Values can be omitted along with equal sign.
| args | the array of command line arguments |
| act | the index of actually parsed argument |
| value | the argument as an Array<{key: String, value: String}> |
| advance | 2 (the whole key/value list is one string without spaces) |
OptparseException if the argument is missing or the one of the key/value pairs has an invalid format.
public static function writerNull( options: Dynamic, field: String, value: Dynamic )
Null option writer. Used when the processed option doesn’t have any argument or when the previously parsed argument doesn’t need to be stored.
| options | the object holding all the option fields |
| field | the name of the field to store value in |
| value | the previously parsed value to be stored |
public static function writerStoreTrue( options: Dynamic, field: String, value: Dynamic )
True boolean value option writer. Stores true into the specified field as a Bool.
| options | the object holding all the option fields |
| field | the name of the field to store value in |
| value | the previously parsed value to be stored |
public static function writerStoreFalse( options: Dynamic, field: String, value: Dynamic )
False boolean value option writer. Stores false into the specified field as a Bool.
| options | the object holding all the option fields |
| field | the name of the field to store value in |
| value | the previously parsed value to be stored |
public static function writerIncrement( options: Dynamic, field: String, value: Dynamic )
Increment option writer. Increments the specified field by one.
| options | the object holding all the option fields |
| field | the name of the field to store value in |
| value | the previously parsed value to be stored |
public static function writerAppend( options: Dynamic, field: String, value: Dynamic )
Array append option writer. Appends the previously parsed argument to the specified array field.
| options | the object holding all the option fields |
| field | the name of the field to store value in |
| value | the previously parsed value to be stored |
public static function makeWriterStoreConst( user_const: Dynamic ): Dynamic -> String -> Dynamic -> Void
Constant option writer creator. Returns a writer function which stores the specified value into the option field.
| user_const | the value to be stored |
The appropriate option writer function.
The value read by a reader function.
value: Dynamic
How many parameters has been parsed by the reader function.
advance: Int
Constructor
public function new( message: String, arg: String, arg_pos: Int )
Converts the exception to a string.
public function toString()
Constructor.
public function new()
Adds a new command line option to the parser.
public function addOption( short: String, long: String, field: String, reader: OptionReader, writer: OptionWriter, ?help: String, ?help_arg: String )
Parses the command line arguments according to the previously specified options by addOption.
public function parse( options: Dynamic, args: Array<String>, start: Int = 0 ): Int
Generates option usage help from the previously specified help and help_arg paramteres in addOption.
public function getHelp(): StringBuf
Null option reader.
public static function readerNull( args: Array<String>, act: Int ): ReaderResult
String option reader.
public static function readerString( args: Array<String>, act: Int ): ReaderResult
Integer option reader.
public static function readerInt( args: Array<String>, act: Int ): ReaderResult
Float option reader.
public static function readerFloat( args: Array<String>, act: Int ): ReaderResult
Key/value pair list option reader.
public static function readerKVArray( args: Array<String>, act: Int ): ReaderResult
Null option writer.
public static function writerNull( options: Dynamic, field: String, value: Dynamic )
Store option writer.
public static function writerStore( options: Dynamic, field: String, value: Dynamic )
True boolean value option writer.
public static function writerStoreTrue( options: Dynamic, field: String, value: Dynamic )
False boolean value option writer.
public static function writerStoreFalse( options: Dynamic, field: String, value: Dynamic )
Increment option writer.
public static function writerIncrement( options: Dynamic, field: String, value: Dynamic )
Array append option writer.
public static function writerAppend( options: Dynamic, field: String, value: Dynamic )
Constant option writer creator.
public static function makeWriterStoreConst( user_const: Dynamic ): Dynamic -> String -> Dynamic -> Void