CMDArgumentHandle - Macro206/CMDKit-Framework GitHub Wiki
CMDArgumentHandle is used to facilitate interpretation of a program's arguments. It maintains a list of valid options and of their arguments, and can even print a list of invalid options (options supplied to the program that aren't in the list of valid options).
NSString *programName
The name of the program to display when printing invalid options.
NSString *version
The version of the program to display when printing invalid options.
id<CMDPrintingDelegate> delegate
The argument handle's delegate. Required for printing program usage (and program help, although this optional).
+(id)argumentHandleWithArguments:(const char *[])arguments count:(int)count
The default method to create CMDArgumentHandle
objects. Only one argument handle is necessary per program.
arguments
should be argv
and count
should be argc
.
-(BOOL)argumentIsOption:(int)n
Returns whether the argument number "n" is an option.
Note: "n" is not an index. The first argument is number 1.
-(BOOL)argumentIsWordOption:(int)n
Returns whether the argument number "n" is a word option.
Note: "n" is not an index. The first argument is number 1.
-(NSString *)getArgument:(int)n
Returns the argument number "n".
Note: "n" is not an index. The first argument is number 1.
-(int)getArgumentIndex:(NSString *)argument
Returns the index of argument
.
Note: "n" is an index. The first argument is at index 0.
-(NSArray *)getArgumentsForOption:(CMDOption *)option
Returns the arguments that follow a given option.
Note: option
must be part of the argument handle's valid options.
-(int)numberOfArguments
Returns the number of arguments (equivalent to argc
).
Note: includes the name of the program (because it's always the first argument).
-(BOOL)optionIsSpecified:(CMDOption *)option
Returns whether the given option is specified.
Note: option
must be part of the argument handle's valid options.
-(BOOL)readValidOptions:(NSArray *)validOptions
The argument handle will mark every option in validOptions
as a valid option.
The array should contain CMDOption
objects - every option that the program has.
This method returns NO
if any of the objects in the array are not of the class CMDOption
.
-(BOOL)readInvalidOptions
Scans through the arguments and checks if any of the options are invalid. If so, it returns YES
.
Only call this method after readValidOptions:
has been called.
-(void)printInvalidOptions
Prints a list of the options supplied as arguments to the program that were invalid.