Skip to content

yousry/ArgumentParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Argument Parser

Create a command line parser from a JSON definition.

This utility class parses command-line program arguments and imitates the gnu-argp behavior. Instead of a C-Struct a JSON-Structure is used to describe the parser.

Example:

#import "YAParser.h"

...

int main(int argc, const char* argv[]) 
{

@autoreleasepool {
   YAParser* parser = [[YAParser alloc] init];
   parser.versionTag = @"Version 0.42";
   parser.authorTag = @"Report bugs to <GrouchoM@example.com>

  [parser createParseTreeFromFile:@"parser.json"];

  NSDictionary* options = [parser parseCommandLime: argv Count: argc ];

  NSLog(@"My Options: %@", options);

}}

A parser definition looks like this:


{
  "Doc":"myApp -- Something wonderful will happen.",
	"Argument":{"Argument":"INPUT", "Doc":"A short Description"},

	"Options":[
		{"Name":"outfile", "Key":"o", "Argument":"OUTFILE", "Doc":"Resulting output"}, 
		{"Name":"withoutargument", "Key":"w", "Doc":"Option without argument."}
	]
}

About

Create a command line parser from a JSON definition .

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published