]>
git.saurik.com Git - apple/security.git/blob - lib/SecArgParse.h
2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
33 /* This is a poor simulacrum of python's argparse library. To use, create an arguments struct, including an array of
34 * argument elements, and pass the struct (along with argv+argc) to options_parse(). This is one-shot argument parsing:
35 * you must set pointers for *argument and *flag in each option to receive the results of the argument parsing.
37 * Currently does not support:
38 * non-string arguments
40 * relationships between arguments
41 * detecting meaningless option configurations
44 * static struct argument options[] = {
45 * { .shortname='p', .longname="perfcounters", .flag=&perfCounters, .flagval=true, .description="Print performance counters"},
46 * { .longname="test", .flag=&test, .flagval=true, .description="test long option"},
47 * { .command="resync", .flag=&resync, .flagval=true, .description="Initiate a resync"},
48 * { .positional_name="positional", .positional_optional=false, .argument=&position, .description = "Positional argument" },
49 * { .shortname='a', .longname="asdf", .argname="number", .argument=&asdf, .description = "Long arg with argument" },
52 * static struct arguments args = {
53 * .programname="testctl",
54 * .description="Control and report",
55 * .arguments = options,
58 * Note: this library automatically adds a '-h' and a '--help' operation. Don't try to override this.
65 char* positional_name
;
66 bool positional_optional
;
79 struct argument
* arguments
;
82 bool options_parse(int argc
, char * const *argv
, struct arguments
* args
);
83 void print_usage(struct arguments
* args
);
85 #endif /* SecArgParse_h */