#ifndef BOKF_COMMANDS_H #define BOKF_COMMANDS_H #include #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