fix multiple optional arguments
Assuming the argument definition "?xy", it was previously not possible to specify only x. Also, the syntax will now be shown as "[x [y]]" instead of "[x] [y]".
This commit is contained in:
parent
e925db2b98
commit
4f0c8e0356
@ -163,7 +163,10 @@ static enum command_parse_status command_extract_arguments(struct command_base*
|
|||||||
token = list_get_first(tokens);
|
token = list_get_first(tokens);
|
||||||
if (!token || !*token)
|
if (!token || !*token)
|
||||||
{
|
{
|
||||||
status = (arg_code == '?' ? cmd_status_ok : cmd_status_missing_args);
|
if (arg_code == '?' || opt == 1)
|
||||||
|
status = cmd_status_ok;
|
||||||
|
else
|
||||||
|
status = cmd_status_missing_args;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +260,7 @@ static enum command_parse_status command_extract_arguments(struct command_base*
|
|||||||
{
|
{
|
||||||
hub_free(data);
|
hub_free(data);
|
||||||
data = NULL;
|
data = NULL;
|
||||||
return cmd_status_arg_number;
|
status = cmd_status_arg_number;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -360,10 +363,13 @@ void command_get_syntax(struct command_handle* handler, struct cbuffer* buf)
|
|||||||
{
|
{
|
||||||
for (n = 0; n < strlen(handler->args); n++)
|
for (n = 0; n < strlen(handler->args); n++)
|
||||||
{
|
{
|
||||||
if (n > 0 && !opt) cbuf_append(buf, " ");
|
if (n > 0)
|
||||||
|
cbuf_append(buf, " ");
|
||||||
|
if (opt)
|
||||||
|
cbuf_append(buf, "[");
|
||||||
switch (handler->args[n])
|
switch (handler->args[n])
|
||||||
{
|
{
|
||||||
case '?': cbuf_append(buf, "["); opt = 1; continue;
|
case '?': opt = 1; continue;
|
||||||
case 'n': cbuf_append(buf, "<nick>"); break;
|
case 'n': cbuf_append(buf, "<nick>"); break;
|
||||||
case 'u': cbuf_append(buf, "<user>"); break;
|
case 'u': cbuf_append(buf, "<user>"); break;
|
||||||
case 'i': cbuf_append(buf, "<cid>"); break;
|
case 'i': cbuf_append(buf, "<cid>"); break;
|
||||||
@ -376,11 +382,10 @@ void command_get_syntax(struct command_handle* handler, struct cbuffer* buf)
|
|||||||
case 'N': cbuf_append(buf, "<number>"); break;
|
case 'N': cbuf_append(buf, "<number>"); break;
|
||||||
}
|
}
|
||||||
if (opt)
|
if (opt)
|
||||||
{
|
opt++;
|
||||||
cbuf_append(buf, "]");
|
|
||||||
opt = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
while (opt--)
|
||||||
|
cbuf_append(buf, "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ struct hub_command
|
|||||||
{
|
{
|
||||||
const char* message; /**<<< "The complete message." */
|
const char* message; /**<<< "The complete message." */
|
||||||
char* prefix; /**<<< "The prefix extracted from the message." */
|
char* prefix; /**<<< "The prefix extracted from the message." */
|
||||||
struct linked_list* args; /**<<< "List of all parsed arguments from the message. Type depends on expectations." */
|
struct linked_list* args; /**<<< "List of arguments of type struct hub_command_arg_data. Parsed from message." */
|
||||||
enum command_parse_status status; /**<<< "Status of the hub_command." */
|
enum command_parse_status status; /**<<< "Status of the hub_command." */
|
||||||
command_handler handler; /**<<< "The function handler to call in order to invoke this command." */
|
command_handler handler; /**<<< "The function handler to call in order to invoke this command." */
|
||||||
const struct hub_user* user; /**<<< "The user who invoked this command." */
|
const struct hub_user* user; /**<<< "The user who invoked this command." */
|
||||||
|
Loading…
Reference in New Issue
Block a user