Re: command line arguments
Re: command line arguments
- Subject: Re: command line arguments
- From: judihuigeisschaes <email@hidden>
- Date: Tue, 22 Mar 2005 13:31:03 +0100
Thanks, great. Exactly what I was looking for!
Just one last question. Does this also work with gnustep environment or
is this a specific enhancement made by Apple? And more generally, is
there somewhere a kind of compatibility check? (I am developing on my
mac, but it would be cool if I could use my programs on the central
linux cluster we have.
Thanks again
Roman
Chris Parker schrieb:
On Mar 21, 2005, at 11:01 AM, Will Mason wrote:
--- Dan Saul <email@hidden <mailto:email@hidden>>
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
<email@hidden <mailto:email@hidden>>
wrote:
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:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSUserDefaults.html#//apple_ref/occ/cl/NSUserDefaults
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 = [[NSUserDefaults 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.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden