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
|
#ifndef BOKF_COMMANDS_H
#define BOKF_COMMANDS_H
#include <stddef.h>
#include "protocol.h"
#include "yyjson.h"
enum cmd_perm {
PERM_PUBLIC = 0,
PERM_READ,
PERM_WRITE,
PERM_OWNER,
PERM_ADMIN
};
enum arg_type { ARG_STR, ARG_INT, ARG_BOOL, ARG_ENUM, ARG_DATE, ARG_JSON };
struct cmd_arg {
const char *name;
enum arg_type type;
int required; /* 1 = must be present; ARG_STR/ARG_ENUM must be non-empty */
const char *def; /* default as text, or NULL */
const char *values;/* ARG_ENUM: comma-separated allowed values, else NULL */
const char *desc; /* one-line description for describe, may be NULL */
};
struct command {
const char *name;
const char *summary;
enum cmd_perm perm;
int need_org;
int mutating;
int dry_run;
yyjson_mut_val *(*fn)(struct req *r);
const struct cmd_arg *args;
size_t nargs;
};
struct cmd_table {
const struct command *cmds;
size_t n;
};
#define CMD_ARGS(a) (a), (sizeof (a) / sizeof (a)[0])
extern const struct cmd_table *const g_command_tables[];
extern const size_t g_command_tables_count;
int command_validate_args(const struct command *cmd, yyjson_val *args,
char *err, size_t errlen);
const struct command *command_find(const char *name);
const char *perm_name(enum cmd_perm p);
const char *perm_scope(enum cmd_perm p);
#endif
|