-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathcommander.h
More file actions
83 lines (62 loc) · 1.35 KB
/
commander.h
File metadata and controls
83 lines (62 loc) · 1.35 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// commander.h
//
// Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
//
#ifndef COMMANDER_H
#define COMMANDER_H
/*
* Max options that can be defined.
*/
#ifndef COMMANDER_MAX_OPTIONS
#define COMMANDER_MAX_OPTIONS 32
#endif
/*
* Max arguments that can be passed.
*/
#ifndef COMMANDER_MAX_ARGS
#define COMMANDER_MAX_ARGS 32
#endif
/*
* Command struct.
*/
struct command;
/*
* Option callback.
*/
typedef void (* command_callback_t)(struct command *self);
/*
* Command option.
*/
typedef struct {
int optional_arg;
int required_arg;
char *argname;
char *large;
const char *small;
const char *large_with_arg;
const char *description;
command_callback_t cb;
} command_option_t;
/*
* Command.
*/
typedef struct command_t{
void *data;
const char *usage;
const char *arg;
const char *name;
const char *version;
int option_count;
command_option_t options[COMMANDER_MAX_OPTIONS];
int argc;
char *argv[COMMANDER_MAX_ARGS];
char **nargv;
} command_t;
// prototypes
void command_init(command_t *self, const char *name, const char *version);
void command_free(command_t *self);
void command_help(command_t *self);
void command_option(command_t *self, const char *small, const char *large, const char *desc, command_callback_t cb);
void command_parse(command_t *self, int argc, char **argv);
#endif /* COMMANDER_H */