Skip to content

Commit

Permalink
Add SHOW HELP; command (#669)
Browse files Browse the repository at this point in the history
* Add SHOW HELP; command

* Removed extra function

* Format

---------

Co-authored-by: CommanderKeynes <[email protected]>
  • Loading branch information
AndrewJackson2020 and CommanderKeynes authored Aug 17, 2024
1 parent 1868a78 commit 588b861
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
32 changes: 32 additions & 0 deletions sources/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ typedef enum {
OD_LSERVER_PREP_STMTS,
OD_LCLIENTS,
OD_LLISTS,
OD_LHELP,
OD_LSET,
OD_LCREATE,
OD_LDROP,
Expand All @@ -37,6 +38,7 @@ typedef enum {
static od_keyword_t od_console_keywords[] = {
od_keyword("kill_client", OD_LKILL_CLIENT),
od_keyword("reload", OD_LRELOAD),
od_keyword("help", OD_LHELP),
od_keyword("show", OD_LSHOW),
od_keyword("stats", OD_LSTATS),
od_keyword("servers", OD_LSERVERS),
Expand Down Expand Up @@ -274,6 +276,34 @@ static int od_console_show_err_router_stats_cb(od_error_logger_t *l,
return od_console_show_router_stats_err_add(stream, l);
}

static inline int od_console_show_help(od_client_t *client,
machine_msg_t *stream)
{
assert(stream);

char msg[OD_QRY_MAX_SZ];
int msg_len;
va_list args;

char *message =
"\n"
"Console usage\n"
"\tSHOW STATS|HELP|POOLS|POOLS_EXTENDED|DATABASES|SERVER_PREP_STMTS|SERVERS|CLIENTS\n"
"\tSHOW LISTS|ERRORS|ERRORS_PER_ROUTE|VERSION|LISTEN|STORAGES\n"
"\tKILL_CLIENT <client_id>\n"
"\tRELOAD\n"
"\tSET key=arg\n"
"\tCREATE <module_path>\n"
"\tDROP SERVERS|MODULE <servers>|<module>";
stream = kiwi_be_write_notice_console_usage(stream, message);

int rc = kiwi_be_write_complete(stream, "SHOW", 5);
if (rc == NOT_OK_RESPONSE) {
return rc;
}
return rc;
}

static inline int od_console_show_stats(od_client_t *client,
machine_msg_t *stream)
{
Expand Down Expand Up @@ -1719,6 +1749,8 @@ static inline int od_console_show(od_client_t *client, machine_msg_t *stream,
switch (keyword->id) {
case OD_LSTATS:
return od_console_show_stats(client, stream);
case OD_LHELP:
return od_console_show_help(client, stream);
case OD_LPOOLS:
return od_console_show_pools(client, stream, false);
case OD_LPOOLS_EXTENDED:
Expand Down
8 changes: 8 additions & 0 deletions third_party/kiwi/kiwi/be_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ kiwi_be_write_notice_as(machine_msg_t *msg, char *severity, int severity_len,
return msg;
}

KIWI_API static inline machine_msg_t *
kiwi_be_write_notice_console_usage(machine_msg_t *msg, char *detail)
{
return kiwi_be_write_notice_as(msg, "NOTICE", 7,
KIWI_SUCCESSFUL_COMPLETION, NULL, 0,
NULL, 0, detail, strlen(detail));
}

KIWI_API static inline machine_msg_t *
kiwi_be_write_notice_info(machine_msg_t *msg, char *message, int len)
{
Expand Down

0 comments on commit 588b861

Please sign in to comment.