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

SwarmObject

Methods

Phase: Creating

Phase: Setting

Phase: Using

Examples

Example objectbase/Arguments/1.

Let's say you want to add a new argument, say `protocol' to your standard 
list of command.  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             Run with a random seed
  -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@santafe.edu. 
-----------------------

To implement this you need to make your own subclass of Arguments
like the following:

#import <objectbase/Arguments.h>

@interface MySwarmAppArguments: Arguments
{
  const char *protocolArg;
}
- (const char *)getProtocolArg;
@end

@implementation MySwarmAppArguments

+ createBegin: 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;					  
}