Created
September 28, 2012 21:15
-
-
Save mysteriouspants/3802114 to your computer and use it in GitHub Desktop.
FSArgumentParser Sample Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import "FSArguments.h" | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
FSArgumentSignature * helpFlag = [FSArgumentSignature argumentSignatureWithFormat:@"[-h --help]"]; | |
FSArgumentSignature * inFileFlag = [FSArgumentSignature argumentSignatureWithFormat:@"[-i --in-file]={1,}"]; | |
FSArgumentSignature * outFileFlag = [FSArgumentSignature argumentSignatureWithFormat:@"[-o --out-file]="]; | |
NSSet * signatures = [NSSet setWithObjects:helpFlag, inFileFlag, outFileFlag, nil]; | |
FSArgumentPackage * package = [[NSProcessInfo processInfo] fsargs_parseArgumentsWithSignatures:signatures]; | |
if ([package booleanValueOfSignature:helpFlag]) { | |
printf("My Tool v1\n"); | |
printf("\n"); | |
printf(" my-tool -h -i file1 file2 -o file\n"); | |
printf("\n"); | |
printf(" -h --help print out this message\n"); | |
printf(" -i --in-file file... input files\n"); | |
printf(" -o --out-file file output file\n"); | |
return 0; | |
} | |
if (0==[package countOfSignature:inFileFlag]) { | |
printf("You didn't specify an input files.\n"); | |
return -1; | |
} else if (0==[package countOfSignature:outFileFlag]) { | |
printf("You didn't specify an output file.\n"); | |
return -1; | |
} | |
/* presumably you'd do something interesting here, like * | |
* maybe concatenate all the files into the output file * | |
* for kicks and giggles. */ | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment