diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2020-10-15 20:38:43 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2020-10-15 20:38:43 +0200 |
commit | 939b16230ce7dfe46eaa2d12d810e1c69bea4e1a (patch) | |
tree | 5d45262ecc6101ac3329cc691f04631970834991 /src/plugins | |
parent | c3707bb6e1ba033a3131224bd6e43437e2c46c89 (diff) | |
download | weechat-939b16230ce7dfe46eaa2d12d810e1c69bea4e1a.zip |
script: allow command /script list when option script.scripts.download_enabled is set to off (closes #1574)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/script/script-action.c | 27 | ||||
-rw-r--r-- | src/plugins/script/script-action.h | 2 | ||||
-rw-r--r-- | src/plugins/script/script-command.c | 27 | ||||
-rw-r--r-- | src/plugins/script/script-repo.c | 2 | ||||
-rw-r--r-- | src/plugins/script/script.c | 19 | ||||
-rw-r--r-- | src/plugins/script/script.h | 2 |
6 files changed, 52 insertions, 27 deletions
diff --git a/src/plugins/script/script-action.c b/src/plugins/script/script-action.c index 47794a1b7..05c86f299 100644 --- a/src/plugins/script/script-action.c +++ b/src/plugins/script/script-action.c @@ -636,7 +636,7 @@ script_action_run_install (int quiet) char *filename, *url; struct t_hashtable *options; - if (!script_download_enabled ()) + if (!script_download_enabled (1)) return; while (1) @@ -1080,7 +1080,7 @@ script_action_run_show (const char *name, int quiet) char *filename, *url; struct t_hashtable *options; - if (!script_download_enabled ()) + if (!script_download_enabled (1)) return; if (name) @@ -1510,12 +1510,17 @@ script_action_run_all () /* * Schedules an action. * - * If "need_repository" is 1, then the action will be executed only when the - * repository file is up-to-date. + * If "need_repository" is 1: + * - if repository is up-to-date: action is executed + * - if "error_repository" is 0: action is executed otherwise the action is + * ignored + * else action is executed. */ void -script_action_schedule (const char *action, int need_repository, int quiet) +script_action_schedule (const char *action, + int need_repository, int error_repository, + int quiet) { /* create again "script" directory, just in case it has been removed */ if (!weechat_mkdir_home (SCRIPT_PLUGIN_NAME, 0755)) @@ -1533,8 +1538,18 @@ script_action_schedule (const char *action, int need_repository, int quiet) } else { - if (!script_repo_file_update (quiet)) + if (!error_repository && !script_download_enabled (0)) + { + /* + * the action can be executed even without repository + * (example: /script list) + */ + script_action_run_all (); + } + else if (!script_repo_file_update (quiet)) + { script_action_clear (); + } } } else diff --git a/src/plugins/script/script-action.h b/src/plugins/script/script-action.h index 05738e449..2077d2edd 100644 --- a/src/plugins/script/script-action.h +++ b/src/plugins/script/script-action.h @@ -24,7 +24,7 @@ extern char **script_actions; extern int script_action_run_all (); extern void script_action_schedule (const char *action, int need_repository, - int quiet); + int error_repository, int quiet); extern void script_action_end (); #endif /* WEECHAT_PLUGIN_SCRIPT_ACTION_H */ diff --git a/src/plugins/script/script-command.c b/src/plugins/script/script-command.c index de5dba3a7..6463ef291 100644 --- a/src/plugins/script/script-command.c +++ b/src/plugins/script/script-command.c @@ -37,8 +37,9 @@ */ void -script_command_action (struct t_gui_buffer *buffer, const char *action, - const char *arguments, int need_repository) +script_command_action (struct t_gui_buffer *buffer, + const char *action, const char *arguments, + int need_repository, int error_repository) { struct t_script_repo *ptr_script; char str_action[4096]; @@ -71,7 +72,8 @@ script_command_action (struct t_gui_buffer *buffer, const char *action, (quiet) ? "-q " : "", action, ptr_script->name_with_extension); - script_action_schedule (str_action, need_repository, quiet); + script_action_schedule (str_action, need_repository, + error_repository, quiet); } } else @@ -81,7 +83,8 @@ script_command_action (struct t_gui_buffer *buffer, const char *action, (quiet) ? "-q " : "", action, arguments); - script_action_schedule (str_action, need_repository, quiet); + script_action_schedule (str_action, need_repository, + error_repository, quiet); } } else if (script_buffer && (buffer == script_buffer)) @@ -95,7 +98,8 @@ script_command_action (struct t_gui_buffer *buffer, const char *action, snprintf (str_action, sizeof (str_action), "-q %s", action); - script_action_schedule (str_action, need_repository, 1); + script_action_schedule (str_action, need_repository, + error_repository, 1); } else { @@ -109,7 +113,8 @@ script_command_action (struct t_gui_buffer *buffer, const char *action, "-q %s %s", action, ptr_script->name_with_extension); - script_action_schedule (str_action, need_repository, 1); + script_action_schedule (str_action, need_repository, + error_repository, 1); } } } @@ -135,7 +140,7 @@ script_command_script (const void *pointer, void *data, if (argc == 1) { - script_action_schedule ("buffer", 1, 0); + script_action_schedule ("buffer", 1, 1, 0); return WEECHAT_RC_OK; } @@ -159,13 +164,13 @@ script_command_script (const void *pointer, void *data, script_repo_filter_scripts ((argc > 2) ? argv_eol[2] : NULL); else script_repo_set_filter ((argc > 2) ? argv_eol[2] : NULL); - script_action_schedule ("buffer", 1, 0); + script_action_schedule ("buffer", 1, 1, 0); return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[1], "list") == 0) { - script_action_schedule (argv_eol[1], 1, 0); + script_action_schedule (argv_eol[1], 1, 0, 0); return WEECHAT_RC_OK; } @@ -179,6 +184,7 @@ script_command_script (const void *pointer, void *data, script_command_action (buffer, argv[1], (argc > 2) ? argv_eol[2] : NULL, + 0, 0); return WEECHAT_RC_OK; } @@ -193,13 +199,14 @@ script_command_script (const void *pointer, void *data, script_command_action (buffer, argv[1], (argc > 2) ? argv_eol[2] : NULL, + 1, 1); return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[1], "upgrade") == 0) { - script_action_schedule ("upgrade", 1, 0); + script_action_schedule ("upgrade", 1, 1, 0); return WEECHAT_RC_OK; } diff --git a/src/plugins/script/script-repo.c b/src/plugins/script/script-repo.c index a218bc9d9..692cff27b 100644 --- a/src/plugins/script/script-repo.c +++ b/src/plugins/script/script-repo.c @@ -1502,7 +1502,7 @@ script_repo_file_update (int quiet) char *filename, *url; struct t_hashtable *options; - if (!script_download_enabled ()) + if (!script_download_enabled (1)) return 0; script_repo_remove_all (); diff --git a/src/plugins/script/script.c b/src/plugins/script/script.c index 9d67ea5f7..9fc9a1f21 100644 --- a/src/plugins/script/script.c +++ b/src/plugins/script/script.c @@ -102,22 +102,25 @@ script_language_search_by_extension (const char *extension) * Checks if download of scripts is enabled. * * Returns: - * 0: download NOT enabled (an error is displayed) + * 0: download NOT enabled (an error is displayed if display_error is 1) * 1: download enabled */ int -script_download_enabled () +script_download_enabled (int display_error) { if (weechat_config_boolean (script_config_scripts_download_enabled)) return 1; - /* download not enabled: display an error */ - weechat_printf (NULL, - _("%s%s: download of scripts is disabled by default; " - "see /help script.scripts.download_enabled"), - weechat_prefix ("error"), - SCRIPT_PLUGIN_NAME); + if (display_error) + { + /* download not enabled: display an error */ + weechat_printf (NULL, + _("%s%s: download of scripts is disabled by default; " + "see /help script.scripts.download_enabled"), + weechat_prefix ("error"), + SCRIPT_PLUGIN_NAME); + } return 0; } diff --git a/src/plugins/script/script.h b/src/plugins/script/script.h index 11106e350..e9c6b44a9 100644 --- a/src/plugins/script/script.h +++ b/src/plugins/script/script.h @@ -34,7 +34,7 @@ extern struct t_hashtable *script_loaded; extern int script_language_search (const char *language); extern int script_language_search_by_extension (const char *extension); -extern int script_download_enabled (); +extern int script_download_enabled (int display_error); extern char *script_build_download_url (const char *url); extern void script_get_loaded_plugins (); extern void script_get_scripts (); |