diff options
Diffstat (limited to 'src/commands.h')
| -rw-r--r-- | src/commands.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/commands.h b/src/commands.h index d04affc..e3168a5 100644 --- a/src/commands.h +++ b/src/commands.h @@ -4,6 +4,7 @@ #include <stddef.h> #include "protocol.h" +#include "yyjson.h" enum cmd_perm { PERM_PUBLIC = 0, @@ -13,6 +14,17 @@ enum cmd_perm { 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; @@ -21,11 +33,17 @@ struct command { int mutating; int dry_run; yyjson_mut_val *(*fn)(struct req *r); + const struct cmd_arg *args; + size_t nargs; }; +#define CMD_ARGS(a) (a), (sizeof (a) / sizeof (a)[0]) + extern const struct command g_commands[]; extern const size_t g_commands_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); |
