summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-07-11 03:27:59 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-07-11 03:29:52 +0200
commita24c068a3b5ebac3bcbb0494a7e96217d7aa0c88 (patch)
tree0f397cc7bde02a41e91ebecf89782f0105657380
parentb987b2cc645c0b56ae0dd98b043ded476dcbdd1c (diff)
downloadxK-a24c068a3b5ebac3bcbb0494a7e96217d7aa0c88.tar.gz
xK-a24c068a3b5ebac3bcbb0494a7e96217d7aa0c88.tar.xz
xK-a24c068a3b5ebac3bcbb0494a7e96217d7aa0c88.zip
degesch: mostly finish /alias sans name checking
-rw-r--r--degesch.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/degesch.c b/degesch.c
index 86b9a0e..620e748 100644
--- a/degesch.c
+++ b/degesch.c
@@ -6818,9 +6818,15 @@ show_aliases_list (struct app_context *ctx)
log_global_indent (ctx, "");
log_global_indent (ctx, "Aliases:");
- struct str_map_iter iter;
- str_map_iter_init (&iter, get_aliases_config (ctx));
+ struct str_map *aliases = get_aliases_config (ctx);
+ if (!aliases->len)
+ {
+ log_global_indent (ctx, " (none)");
+ return true;
+ }
+ struct str_map_iter iter;
+ str_map_iter_init (&iter, aliases);
struct config_item_ *alias;
while ((alias = str_map_iter_next (&iter)))
{
@@ -6839,15 +6845,22 @@ show_aliases_list (struct app_context *ctx)
static bool
handle_command_alias (struct handler_args *a)
{
- char *name = cut_word (&a->arguments);
- if (!*name)
+ if (!*a->arguments)
return show_aliases_list (a->ctx);
- char *definition = cut_word (&a->arguments);
- if (!*definition)
+ // TODO: validate the name; maybe also while loading configuration
+ char *name = cut_word (&a->arguments);
+ if (!*a->arguments)
return false;
- // TODO: set the alias "name" to "definition"
+ struct config_item_ *alias = config_item_string_from_cstr (a->arguments);
+
+ struct str definition;
+ str_init (&definition);
+ config_item_write_string (&definition, &alias->value.string);
+ str_map_set (get_aliases_config (a->ctx), name, alias);
+ log_global_status (a->ctx, "Created alias /#s: #s", name, definition.str);
+ str_free (&definition);
return true;
}