From 251056d02420e3d3321f3d22ba649c1ba4e203aa Mon Sep 17 00:00:00 2001 From: Martin Price Date: Tue, 2 Jul 2024 22:35:48 +0100 Subject: [PATCH] Handle incorrect cache argument --- commands/cache.bee.inc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/commands/cache.bee.inc b/commands/cache.bee.inc index ea3632e4..def9d540 100644 --- a/commands/cache.bee.inc +++ b/commands/cache.bee.inc @@ -14,7 +14,7 @@ function cache_bee_command() { 'callback' => 'cache_clear_bee_command', 'group' => 'miscellaneous', 'arguments' => array( - 'cache' => bt('The name of the cache to clear. Leave blank to see a list of available caches.'), + 'cache' => bt('The name of the cache to clear (not case sensitive). Leave blank to see a list of available caches.'), ), 'optional_arguments' => array('cache'), 'aliases' => array('cc'), @@ -22,6 +22,7 @@ function cache_bee_command() { 'examples' => array( 'bee cache-clear menu' => bt('Clear the menu cache.'), 'bee cache-clear all' => bt('Clear all caches.'), + 'bee cache-clear css_js' => bt('Clear the CSS & JS cache.'), 'bee cache-clear' => bt('Select the cache to clear from a list of available ones.'), ), ), @@ -36,7 +37,7 @@ function cache_clear_bee_command($arguments, $options) { $cache_list = array( 'all' => bt('All'), 'core' => bt('Core (page, admin bar, etc.)'), - 'css_js' => bt('CSS & JS'), + 'css_js' => bt('CSS & JS [css_js]'), 'entity' => bt('Entity'), 'layout' => bt('Layout'), 'menu' => bt('Menu'), @@ -47,10 +48,19 @@ function cache_clear_bee_command($arguments, $options) { ); // Get the cache to clear. - if (isset($arguments['cache'])) { - $cache = $arguments['cache']; + $cache = isset($arguments['cache']) ? strtolower($arguments['cache']) : NULL; + + // Check the cache. + if (!is_null($cache) && !isset($cache_list[$cache])) { + bee_instant_message(bt("'!cache' is not a valid cache to clear.", array( + "!cache" => $cache, + )) . "\n", 'warning'); // Add additional linebreak before select list. + $cache = NULL; } - else { + + // If either no cache was entered or an invalid cache was entered, offer a + // choice of caches to clear. + if (is_null($cache)) { $cache = bee_choice($cache_list, bt('Select a cache to clear:'), 'all'); }