degesch: print usage on command syntax failure

This commit is contained in:
Přemysl Eric Janouch 2015-04-25 01:49:34 +02:00
parent b2cfbf1501
commit 05d21e8f3d
1 changed files with 40 additions and 43 deletions

View File

@ -2589,7 +2589,7 @@ log_outcoming_notice (struct app_context *ctx,
// --- User input handling -----------------------------------------------------
static void handle_command_help (struct app_context *, char *);
static bool handle_command_help (struct app_context *, char *);
/// Cuts the longest non-whitespace portion of text and advances the pointer
static char *
@ -2642,12 +2642,12 @@ server_command_check (struct app_context *ctx, const char *action)
return false;
}
static void
static bool
handle_command_buffer (struct app_context *ctx, char *arguments)
{
char *action = cut_word (&arguments);
if (try_handle_buffer_goto (ctx, action))
return;
return true;
struct buffer *buffer = NULL;
@ -2684,19 +2684,19 @@ handle_command_buffer (struct app_context *ctx, char *arguments)
{
buffer_send_error (ctx, ctx->global_buffer,
"%s: %s", "No such buffer", which);
return;
return true;
}
if (buffer == ctx->global_buffer)
{
buffer_send_error (ctx, ctx->global_buffer,
"Can't close the global buffer");
return;
return true;
}
if (buffer == ctx->server_buffer)
{
buffer_send_error (ctx, ctx->global_buffer,
"Can't close the server buffer");
return;
return true;
}
if (buffer == ctx->current_buffer)
@ -2704,41 +2704,34 @@ handle_command_buffer (struct app_context *ctx, char *arguments)
buffer_remove (ctx, buffer);
}
else
{
// TODO: show usage (or do something else?)
}
return false;
return true;
}
static void
static bool
handle_command_msg (struct app_context *ctx, char *arguments)
{
if (!server_command_check (ctx, "send messages"))
return;
return true;
if (!*arguments)
{
// TODO: show usage or something
return;
}
return false;
char *target = cut_word (&arguments);
if (!*arguments)
buffer_send_error (ctx, ctx->server_buffer, "No text to send");
else
SEND_AUTOSPLIT_PRIVMSG (ctx, target, arguments);
return true;
}
static void
static bool
handle_command_query (struct app_context *ctx, char *arguments)
{
if (!server_command_check (ctx, "send messages"))
return;
return true;
if (!*arguments)
{
// TODO: show usage or something
return;
}
return false;
char *target = cut_word (&arguments);
if (irc_is_channel (ctx, target))
@ -2750,28 +2743,26 @@ handle_command_query (struct app_context *ctx, char *arguments)
buffer_activate (ctx, irc_get_or_make_user_buffer (ctx, target));
SEND_AUTOSPLIT_PRIVMSG (ctx, target, arguments);
}
return true;
}
static void
static bool
handle_command_notice (struct app_context *ctx, char *arguments)
{
if (!server_command_check (ctx, "send messages"))
return;
return true;
if (!*arguments)
{
// TODO: show usage or something
return;
}
return false;
char *target = cut_word (&arguments);
if (!*arguments)
buffer_send_error (ctx, ctx->server_buffer, "No text to send");
else
SEND_AUTOSPLIT_NOTICE (ctx, target, arguments);
return true;
}
static void
static bool
handle_command_quit (struct app_context *ctx, char *arguments)
{
if (ctx->irc_fd != -1)
@ -2782,13 +2773,14 @@ handle_command_quit (struct app_context *ctx, char *arguments)
irc_send (ctx, "QUIT :%s", PROGRAM_NAME " " PROGRAM_VERSION);
}
initiate_quit (ctx);
return true;
}
static void
static bool
handle_command_join (struct app_context *ctx, char *arguments)
{
if (!server_command_check (ctx, "join"))
return;
return true;
if (*arguments)
// TODO: check if the arguments are in the form of
@ -2809,13 +2801,14 @@ handle_command_join (struct app_context *ctx, char *arguments)
// TODO: send the key if known
irc_send (ctx, "JOIN %s", ctx->current_buffer->channel->name);
}
return true;
}
static void
static bool
handle_command_part (struct app_context *ctx, char *arguments)
{
if (!server_command_check (ctx, "part"))
return;
return true;
if (*arguments)
// TODO: check if the arguments are in the form of "channel(,channel)*"
@ -2834,21 +2827,23 @@ handle_command_part (struct app_context *ctx, char *arguments)
else
irc_send (ctx, "PART %s", ctx->current_buffer->channel->name);
}
return true;
}
static void
static bool
handle_command_quote (struct app_context *ctx, char *arguments)
{
if (!server_command_check (ctx, "quote"))
return;
return true;
irc_send (ctx, arguments);
return true;
}
static struct command_handler
{
const char *name;
void (*handler) (struct app_context *ctx, char *arguments);
bool (*handler) (struct app_context *ctx, char *arguments);
const char *description;
const char *usage;
}
@ -2898,14 +2893,14 @@ g_command_handlers[] =
"command" },
};
static void
static bool
handle_command_help (struct app_context *ctx, char *arguments)
{
if (*arguments)
{
char *command = cut_word (&arguments);
// TODO: search for the command and show specific help
return;
return true;
}
buffer_send_status (ctx, ctx->global_buffer, "Commands:");
@ -2917,6 +2912,7 @@ handle_command_help (struct app_context *ctx, char *arguments)
buffer_send_status (ctx, ctx->global_buffer,
" Arguments: %s", iter->usage);
}
return true;
}
static int
@ -2970,11 +2966,12 @@ process_user_command (struct app_context *ctx, char *command)
return;
struct command_handler *handler = str_map_find (&partial, name);
if (handler)
handler->handler (ctx, command);
else
if (!handler)
buffer_send_error (ctx, ctx->global_buffer,
"%s: %s", "No such command", name);
else if (!handler->handler (ctx, command))
buffer_send_error (ctx, ctx->global_buffer,
"%s: /%s %s", "Usage", handler->name, handler->usage);
}
static void