Arguments

Name

Arguments --  A class that provides customizable command line argument parsing support

Description

A class that provides customizable command line argument parsing support

Protocols adopted by Arguments

Create Drop CREATABLE

Methods

Phase: Creating

Phase: Setting

Phase: Using

Examples

Example defobj/Arguments/1.

 Let's say you want to add a new argument, say `protocol' to your standard 
 list of commands.  In other words you want the following to happen at the
 command line when you type --help.
 ------------------------
 mgd@wijiji[/opt/src/mgd/src/mySwarmApp] $ ./mySwarmApp --help
 Usage: mySwarmApp [OPTION...]
 
   -s, --varyseed             Select random number seed from current time
   -S, --seed=INTEGER         Specify seed for random numbers
   -b, --batch                Run in batch mode
   -m, --mode=MODE            Specify mode of use (for archiving)
   -p, --protocol=PROTOCOL    Set protocol
   -?, --help                 Give this help list
       --usage                Give a short usage message
   -V, --version              Print program version
 
 Mandatory or optional arguments to long options are also mandatory or 
 optional for any corresponding short options.
 
 Report bugs to bug-swarm@swarm.org. 
 -----------------------
 
 To implement this you need to make your own subclass of Arguments
 like the following:
 
 #import <defobj/Arguments.h>
 
 @interface MySwarmAppArguments: Arguments_c
 {
   const char *protocolArg;
 }
 - (const char *)getProtocolArg;
 @end
 
 @implementation MySwarmAppArguments
 
 + createBegin: (id <Zone>)aZone
 {
   static struct argp_option options[] = {
     {"protocol", 'p', "PROTOCOL", 0, "Set protocol", 3},
     { 0 }
   };
   
   MySwarmAppArguments *obj = [super createBegin: aZone];
 
   [obj addOptions: options];
   return obj;
 }
 
 - (int)parseKey: (int)key arg: (const char *)arg
 {
   if (key == 'p')
     {
       protocolArg = arg;
       return 0;
     }
   else
     return [super parseKey: key arg: arg];
 }
 
 - (const char *)getProtocolArg
 {
   return protocolArg;
 }
 
 @end

 To actually invoke this in the main.m program, you do the following:

 int 
 main (int argc, const char ** argv) 
 {
   initSwarmArguments (argc, argv, [MySwarmAppArguments class]);
   
   // the usual - buildObjects:, - buildActions:, - activateIn: calls
   
   return 0;					  
 }