-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.hpp
59 lines (46 loc) · 1.38 KB
/
cli.hpp
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
59
#ifndef CLI_HPP
#define CLI_HPP
#define CLI_OPT_NAME_BUFFER_SIZE 64
namespace cli {
typedef unsigned int uint;
enum OptArgType {
kOptArgType_Int,
kOptArgType_Uint,
kOptArgType_Float,
kOptArgType_String
};
struct Opt {
char name[CLI_OPT_NAME_BUFFER_SIZE];
OptArgType arg_type;
void *arg;
};
enum Status {
kStatus_Ok,
kStatus_InvalidOptArgType,
kStatus_MissingOptArg,
kStatus_InvalidOptArg,
kStatus_UnexpectedOptName,
};
const char *StatusMessage(Status s);
/*
Parses options from arguments passed to the program.
Each option provided at the command-line has its name prefixed with "--" and has
an associated argument following its name. `--kmeans-cluster-count 10` is an
example.
Options must be before positional parameters. Otherwise, the intended
options would be considered positional parameters. For instance, in `encode
--kmeans-cluster-count 10 foreman.mp4`, the option `--kmeans-cluster-count 10`
is before the positional parameter `foreman.mp4`.
Input Parameters:
- argc: number of arguments passed to the program
- argv: all arguments passed to the program
- opts_size: number of options
Output Parameters:
- opts: options
- argi: argument index that is one past that of the last option successfully
parsed. cannot be null
*/
Status ParseOpts(uint argc, char *argv[], Opt opts[], uint opts_size,
uint *argi);
} // namespace cli
#endif // CLI_HPP