CommandLineOption¶
Defines a command-line option for CommandLineParser.
Description¶
This class is used to define an option on the command line. The same option is allowed to have multiple aliases. It is also used to describe how the option is used: it may be a flag (e.g. -v
) or take a value (e.g. -o file
).
Properties¶
PoolStringArray | allowed_args | PoolStringArray( ) |
int | arg_count | 1 |
String | arg_text | "<arg>" |
String | category | "" |
PoolStringArray | default_args | PoolStringArray( ) |
String | description | "" |
bool | hidden | false |
bool | meta | false |
bool | multitoken | false |
PoolStringArray | names | PoolStringArray( ) |
bool | positional | false |
bool | required | false |
Methods¶
void | add_allowed_arg ( String arg ) |
void | add_default_arg ( String arg ) |
void | add_name ( String name ) |
Signals¶
- parsed ( PoolStringArray values )
Emitted after calling CommandLineParser.parse if it returns @GlobalScope.OK. The values
list contains all values that were passed to the option.
Property Descriptions¶
- PoolStringArray allowed_args
Default | PoolStringArray( ) |
Setter | set_allowed_args(value) |
Getter | get_allowed_args() |
A set of values that are allowed by the option. If a different value is passed, the parsing will fail. Empty if any value is allowed.
- int arg_count
Default | 1 |
Setter | set_arg_count(value) |
Getter | get_arg_count() |
The number of arguments required for the option. A value less than 0 means all remaining values up to the next option or the end of the argument list.
- String arg_text
Default | "<arg>" |
Setter | set_arg_text(value) |
Getter | get_arg_text() |
Name for the option arguments that will be displayed in the help message. For example: --input <filename>
, where <filename>
is arg_text
.
- String category
Default | "" |
Setter | set_category(value) |
Getter | get_category() |
Category name, options sharing the same category are grouped together in the help message.
- PoolStringArray default_args
Default | PoolStringArray( ) |
Setter | set_default_args(value) |
Getter | get_default_args() |
A set of values that will be used by default if no value specified.
- String description
Default | "" |
Setter | set_description(value) |
Getter | get_description() |
Description that will be displayed in the help message.
Default | false |
Setter | set_hidden(value) |
Getter | is_hidden() |
If true
, the option will not be displayed in the help message.
- bool meta
Default | false |
Setter | set_as_meta(value) |
Getter | is_meta() |
If true
, the option will be treated as a meta option, such as --help
or --version
. If CommandLineParser parses such option, any required options will not throw an error if they are not specified on the command-line.
- bool multitoken
Default | false |
Setter | set_multitoken(value) |
Getter | is_multitoken() |
If true
, option can be specified multiple times. Total count can be obtained using CommandLineParser.get_occurrence_count.
- PoolStringArray names
Default | PoolStringArray( ) |
Setter | set_names(value) |
Getter | get_names() |
Specifies all valid names (aliases) for this option.
- bool positional
Default | false |
Setter | set_positional(value) |
Getter | is_positional() |
If true
, option can be specified without a name. In this case, the first unparsed option marked as positional will be selected.
- bool required
Default | false |
Setter | set_required(value) |
Getter | is_required() |
If true
, CommandLineParser.parse will return an error if the option was not specified in the argument list.
Method Descriptions¶
- void add_allowed_arg ( String arg )
Appends a new allowed argument to the list of allowed_args.
- void add_default_arg ( String arg )
Appends a new default argument to the list of default_args.
- void add_name ( String name )
Appends a new name (alias) to the list of names.