In order to simplify usage, this class drives the option parsing by running the while loop. When an option is found, Key-Value Coding (KVC) is used to set a key on the target class. Unless overridden, the key to use is the same as the long option. The long option is converted to camel case, if needed. For example the option "long-option" has a default key of "longOption".
Public Member Functions | |
(id) | - initWithTarget: |
Create an option parser with the given target. | |
(id) | - target |
Returns the target object. | |
(void) | - setTarget: |
Sets the target object. | |
(void) | - setGetoptLongOnly: |
If set to YES, parses options with getopt_long_only() instead of getopt_long(). | |
(void) | - addOptionsFromTable: |
Add all options from a null terminated option table. | |
(void) | - addLongOption:shortOption:key:argumentOptions: |
Add an option with both long and short options. | |
(void) | - addLongOption:key:argumentOptions: |
Add an option with no short option. | |
(NSArray *) | - parseOptions |
Parse the options using the arguments and command name from NSProcessInfo. | |
(NSArray *) | - parseOptionsWithArguments:command: |
Parse the options on an array of arguments. | |
Static Public Member Functions | |
(DDGetoptLongParser *) | + optionsWithTarget: |
Create an autoreleased option parser with the given target. |
+ (DDGetoptLongParser *) optionsWithTarget: | (id) | target |
Create an autoreleased option parser with the given target.
target | Object that receives target messages. |
- (id) initWithTarget: | (id) | target |
Create an option parser with the given target.
target | Object that receives target messages. |
- (id) target |
Returns the target object.
- (void) setTarget: | (id) | target |
Sets the target object.
target | The target object |
- (void) setGetoptLongOnly: | (BOOL) | getoptLongOnly |
If set to YES, parses options with getopt_long_only() instead of getopt_long().
getoptLongOnly | YES means parse with getopt_long_only() |
- (void) addOptionsFromTable: | (DDGetoptOption *) | optionTable |
Add all options from a null terminated option table.
The final entry in the table should contain a nil long option and a null short option.
optionTable | An array of DDGetoptOption. |
- (void) addLongOption: | (NSString *) | longOption | ||
shortOption: | (char) | shortOption | ||
key: | (NSString *) | key | ||
argumentOptions: | (DDGetoptArgumentOptions) | argumentOptions | ||
Add an option with both long and short options.
The long option should not contain the double dash ("--"). If you do not want a short option, set it to the zero or the null character.
longOption | The long option | |
shortOption | The short option | |
key | The key use when the option is parsed | |
argumentOptions | Options for this options argument |
- (void) addLongOption: | (NSString *) | longOption | ||
key: | (NSString *) | key | ||
argumentOptions: | (DDGetoptArgumentOptions) | argumentOptions | ||
Add an option with no short option.
longOption | The long option | |
key | The key use when the option is parsed | |
argumentOptions | Options for this options argument |
- (NSArray *) parseOptions |
Parse the options using the arguments and command name from NSProcessInfo.
nil
- (NSArray *) parseOptionsWithArguments: | (NSArray *) | arguments | ||
command: | (NSString *) | command | ||
Parse the options on an array of arguments.
arguments | Array of command line arguments | |
command | Command name to use for error messages. |
nil