On Mar 21, 2005, at 11:01 AM, Will Mason wrote: The class you are looking for is NSProcessInfo.
Although NSProcessInfo gives you access to the arguments, it doesn't help you at all with processing them. He's going to have to use getopt(3) or getopt_long(3).
On Mon, 21 Mar 2005 14:22:31 +0100, judihuigeisschaes Hello
I am looking for command line argument processing support in objective-c/cocoa. I was thinking about something similar to the Getopt::Long library in perl. Is there any such thing available in
cocoa?
It actually depends on how sophisticated you want it to be...
NSUserDefaults can extract various values from keys passed in on the command line.
See:
and the documentation about NSArgumentDomain.
So given a command line like the following:
./someFoundationBasedThing -srcpath /Volumes/Stuff/someDir -dstpath /Volumes/WorkingDir/someNewName
You can do something like this:
NSString *src = "" standardUserDefaults] stringForKey:@"srcpath"];
and voila, src contains "/Volumes/Stuff/someDir"
You can also have a command line like this:
./something -SomeFlag YES
with this code:
BOOL flag = [[NSUserDefaults standardUserDefaults] boolForKey:@"SomeFlag"];
It does not, however deal with things like:
./someFoundationBasedThing -SomeFlag
with the above boolForKey: code and set the flag variable to true (i.e. the presence of the key in the command line is not enough to set the flag - you must have explicit key/value pairs).
.chris
-- Chris Parker Cocoa Frameworks Apple, Inc.
|