1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#ifndef AWS_COMMON_COMMAND_LINE_PARSER_H
#define AWS_COMMON_COMMAND_LINE_PARSER_H
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/common.h>
enum aws_cli_options_has_arg {
AWS_CLI_OPTIONS_NO_ARGUMENT = 0,
AWS_CLI_OPTIONS_REQUIRED_ARGUMENT = 1,
AWS_CLI_OPTIONS_OPTIONAL_ARGUMENT = 2,
};
/* Ignoring padding since we're trying to maintain getopt.h compatibility */
/* NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding) */
struct aws_cli_option {
const char *name;
enum aws_cli_options_has_arg has_arg;
int *flag;
int val;
};
AWS_EXTERN_C_BEGIN
/**
* Initialized to 1 (for where the first argument would be). As arguments are parsed, this number is the index
* of the next argument to parse. Reset this to 1 to parse another set of arguments, or to rerun the parser.
*/
AWS_COMMON_API extern int aws_cli_optind;
/**
* If an option has an argument, when the option is encountered, this will be set to the argument portion.
*/
AWS_COMMON_API extern const char *aws_cli_optarg;
/**
* A mostly compliant implementation of posix getopt_long(). Parses command-line arguments. argc is the number of
* command line arguments passed in argv. optstring contains the legitimate option characters. The option characters
* coorespond to aws_cli_option::val. If the character is followed by a :, the option requires an argument. If it is
* followed by '::', the argument is optional (not implemented yet).
*
* longopts, is an array of struct aws_cli_option. These are the allowed options for the program.
* The last member of the array must be zero initialized.
*
* If longindex is non-null, it will be set to the index in longopts, for the found option.
*
* Returns option val if it was found, '?' if an option was encountered that was not specified in the option string,
* returns -1 when all arguments that can be parsed have been parsed.
*/
AWS_COMMON_API int aws_cli_getopt_long(
int argc,
char *const argv[],
const char *optstring,
const struct aws_cli_option *longopts,
int *longindex);
AWS_EXTERN_C_END
#endif /* AWS_COMMON_COMMAND_LINE_PARSER_H */
|