diff options
author | James Booth <boothj5@gmail.com> | 2017-02-05 21:09:03 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2017-02-05 21:09:03 +0000 |
commit | 286fecf38d218d10366f025faf7cffcb425e19f4 (patch) | |
tree | 331a61f379d7513c8bc9d6db0d852e5fdb0518aa /src/command | |
parent | c405367dfeb3c23bac192a170501e569be934f26 (diff) | |
download | profani-tty-286fecf38d218d10366f025faf7cffcb425e19f4.tar.gz |
Allow installing plugins from directory
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/cmd_funcs.c | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 7f854249..d26ff43f 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -6214,49 +6214,77 @@ cmd_xa(ProfWin *window, const char *const command, gchar **args) gboolean cmd_plugins_install(ProfWin *window, const char *const command, gchar **args) { - char *filename = args[1]; - if (filename == NULL) { + char *path = args[1]; + if (path == NULL) { cons_bad_cmd_usage(command); return TRUE; } // expand ~ to $HOME - if (filename[0] == '~' && filename[1] == '/') { - if (asprintf(&filename, "%s/%s", getenv("HOME"), filename+2) == -1) { + if (path[0] == '~' && path[1] == '/') { + if (asprintf(&path, "%s/%s", getenv("HOME"), path+2) == -1) { return TRUE; } } else { - filename = strdup(filename); + path = strdup(path); } - if (access(filename, R_OK) != 0) { - cons_show("File not found: %s", filename); - free(filename); + if (access(path, R_OK) != 0) { + cons_show("File not found: %s", path); + free(path); return TRUE; } - if (!is_regular_file(filename)) { - cons_show("Not a file: %s", filename); - free(filename); - return TRUE; - } + if (is_regular_file(path)) { + if (!g_str_has_suffix(path, ".py") && !g_str_has_suffix(path, ".so")) { + cons_show("Plugins must have one of the following extensions: '.py' '.so'"); + free(path); + return TRUE; + } - if (!g_str_has_suffix(filename, ".py") && !g_str_has_suffix(filename, ".so")) { - cons_show("Plugins must have one of the following extensions: '.py' '.so'"); - free(filename); + gchar *plugin_name = g_path_get_basename(path); + gboolean result = plugins_install(plugin_name, path); + if (result) { + cons_show("Plugin installed: %s", plugin_name); + } else { + cons_show("Failed to install plugin: %s", plugin_name); + } + g_free(plugin_name); + + free(path); return TRUE; } - gchar *plugin_name = g_path_get_basename(filename); - gboolean result = plugins_install(plugin_name, filename); - if (result) { - cons_show("Plugin installed: %s", plugin_name); - } else { - cons_show("Failed to install plugin: %s", plugin_name); + if (is_dir(path)) { + PluginsInstallResult* result = plugins_install_all(path); + if (result->installed || result->failed) { + if (result->installed) { + cons_show(""); + cons_show("Installed plugins:"); + GSList *curr = result->installed; + while (curr) { + cons_show(" %s", curr->data); + curr = g_slist_next(curr); + } + } + if (result->failed) { + cons_show(""); + cons_show("Failed installs:"); + GSList *curr = result->failed; + while (curr) { + cons_show(" %s", curr->data); + curr = g_slist_next(curr); + } + } + } else { + cons_show("No plugins found in: %s", path); + } + free(path); + plugins_free_install_result(result); + return TRUE; } - g_free(plugin_name); - free(filename); + cons_show("Argument must be a file or directory."); return TRUE; } |