degesch: add aliases to /help and autocomplete
This commit is contained in:
parent
a24c068a3b
commit
8f587117f7
32
degesch.c
32
degesch.c
|
@ -6830,12 +6830,12 @@ show_aliases_list (struct app_context *ctx)
|
||||||
struct config_item_ *alias;
|
struct config_item_ *alias;
|
||||||
while ((alias = str_map_iter_next (&iter)))
|
while ((alias = str_map_iter_next (&iter)))
|
||||||
{
|
{
|
||||||
if (!config_item_type_is_string (alias->type))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
struct str definition;
|
struct str definition;
|
||||||
str_init (&definition);
|
str_init (&definition);
|
||||||
config_item_write_string (&definition, &alias->value.string);
|
if (config_item_type_is_string (alias->type))
|
||||||
|
config_item_write_string (&definition, &alias->value.string);
|
||||||
|
else
|
||||||
|
str_append (&definition, "alias definition is not a string");
|
||||||
log_global_indent (ctx, " /#s: #s", iter.link->key, definition.str);
|
log_global_indent (ctx, " /#s: #s", iter.link->key, definition.str);
|
||||||
str_free (&definition);
|
str_free (&definition);
|
||||||
}
|
}
|
||||||
|
@ -7647,7 +7647,7 @@ static bool
|
||||||
show_command_help (struct app_context *ctx, struct command_handler *handler)
|
show_command_help (struct app_context *ctx, struct command_handler *handler)
|
||||||
{
|
{
|
||||||
log_global_indent (ctx, "");
|
log_global_indent (ctx, "");
|
||||||
log_global_indent (ctx, "#s: #s", handler->name, handler->description);
|
log_global_indent (ctx, "/#s: #s", handler->name, handler->description);
|
||||||
log_global_indent (ctx, " Arguments: #s",
|
log_global_indent (ctx, " Arguments: #s",
|
||||||
handler->usage ? handler->usage : "(none)");
|
handler->usage ? handler->usage : "(none)");
|
||||||
return true;
|
return true;
|
||||||
|
@ -7668,7 +7668,12 @@ handle_command_help (struct handler_args *a)
|
||||||
return show_command_help (ctx, handler);
|
return show_command_help (ctx, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!try_handle_command_help_option (ctx, command))
|
if (try_handle_command_help_option (ctx, command))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (str_map_find (get_aliases_config (ctx), command))
|
||||||
|
log_global_status (ctx, "/#s is an alias", command);
|
||||||
|
else
|
||||||
log_global_error (ctx, "#s: #s", "No such command or option", command);
|
log_global_error (ctx, "#s: #s", "No such command or option", command);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -7786,8 +7791,8 @@ expand_alias (struct app_context *ctx, const char *alias_name, char *input)
|
||||||
if (config_item_type_is_string (entry->type))
|
if (config_item_type_is_string (entry->type))
|
||||||
return expand_alias_definition (&entry->value.string, input);
|
return expand_alias_definition (&entry->value.string, input);
|
||||||
|
|
||||||
log_global_error (ctx, "Error executing `/%s': "
|
log_global_error (ctx, "Error executing `/%s': %s",
|
||||||
"alias definition is not a string", alias_name);
|
alias_name, "alias definition is not a string");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7989,7 +7994,6 @@ static void
|
||||||
complete_command (struct app_context *ctx, struct completion *data,
|
complete_command (struct app_context *ctx, struct completion *data,
|
||||||
const char *word, struct str_vector *output)
|
const char *word, struct str_vector *output)
|
||||||
{
|
{
|
||||||
(void) ctx;
|
|
||||||
(void) data;
|
(void) data;
|
||||||
|
|
||||||
const char *prefix = "";
|
const char *prefix = "";
|
||||||
|
@ -8007,6 +8011,16 @@ complete_command (struct app_context *ctx, struct completion *data,
|
||||||
str_vector_add_owned (output,
|
str_vector_add_owned (output,
|
||||||
xstrdup_printf ("%s%s", prefix, handler->name));
|
xstrdup_printf ("%s%s", prefix, handler->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct str_map_iter iter;
|
||||||
|
str_map_iter_init (&iter, get_aliases_config (ctx));
|
||||||
|
struct config_item_ *alias;
|
||||||
|
while ((alias = str_map_iter_next (&iter)))
|
||||||
|
{
|
||||||
|
if (!strncasecmp_ascii (word, iter.link->key, word_len))
|
||||||
|
str_vector_add_owned (output,
|
||||||
|
xstrdup_printf ("%s%s", prefix, iter.link->key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue