]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli/wait: make the wait command support a more detailed help message
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Feb 2024 16:40:43 +0000 (17:40 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Feb 2024 19:38:08 +0000 (20:38 +0100)
We'll want to add some waiting conditions, so let's support -h to show
the available list, and also print this usage on unknown options.

doc/management.txt
src/cli.c

index c5e5579d37b676916498c882f04710bf9af1b3ca..dfd8eee2f14d2e8fe8ee108228b76d227b9d66be 100644 (file)
@@ -3997,12 +3997,13 @@ update ssl ocsp-response <certfile>
   local tree, its contents will be displayed on the standard output. The format
   is the same as the one described in "show ssl ocsp-response".
 
-wait <delay>
+wait { -h | <delay> }
   This simply waits for the requested delay before continuing. This can be used
   to collect metrics around a specific interval. The default unit for the delay
   is milliseconds, though other units are accepted if suffixed with the usual
-  timer units (s, m, h, d). When used with the 'socat' utility, do not forget
-  to extend socat's close timeout to cover the wait time.
+  timer units (us, ms, s, m, h, d). When used with the 'socat' utility, do not
+  forget to extend socat's close timeout to cover the wait time. Passing "-h"
+  as the first or second argument provides the command's usage.
   Example:
     $ socat -t20 /path/to/socket <<< "show activity; wait 10s; show activity"
 
index acd5b8729ef0828a5d38c56bcb9b43e06fdcc9ed..7c88917a70761c74d5bf88403436ea99effed47d 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -2027,8 +2027,28 @@ static int cli_parse_wait(char **args, char *payload, struct appctx *appctx, voi
                return cli_err(appctx, "Expects a duration in milliseconds.\n");
 
        err = parse_time_err(args[1], &wait_ms, TIME_UNIT_MS);
-       if (err || wait_ms < 1)
-               return cli_err(appctx, "Invalid duration.\n");
+       if (err || wait_ms < 1) {
+               /* in case -h is passed as the first option, continue to the next test */
+               if (strcmp(args[1], "-h") == 0)
+                       args--;
+               else
+                       return cli_err(appctx, "Invalid duration.\n");
+       }
+
+       if (*args[2]) {
+               /* show the command's help either upon request (-h) or error */
+               err = "Usage: wait {-h|<duration>} [condition [args...]]\n"
+                       "  - '-h' displays this help\n"
+                       "  - <duration> is the maximum wait time, optionally suffixed by the unit among\n"
+                       "    'us', 'ms', 's', 'm', 'h', and 'd'. ; the default unit is milliseconds.\n"
+                       "  - <condition> indicates what to wait for. By default, no events aborts the\n"
+                       "    operation, which makes it reliably pause for the specified duration.\n";
+
+               if (strcmp(args[2], "-h") == 0)
+                       return cli_msg(appctx, LOG_INFO, err);
+               else
+                       return cli_err(appctx, err);
+       }
 
        ctx->start = now_ms;
        ctx->deadline = tick_add(now_ms, wait_ms);
@@ -3505,7 +3525,7 @@ static struct cli_kw_list cli_kws = {{ },{
        { { "show", "version", NULL },           "show version                            : show version of the current process",                     cli_parse_show_version, NULL, NULL, NULL, ACCESS_MASTER },
        { { "operator", NULL },                  "operator                                : lower the level of the current CLI session to operator",  cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER},
        { { "user", NULL },                      "user                                    : lower the level of the current CLI session to user",      cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER},
-       { { "wait", NULL },                      "wait <ms>                               : wait the specified delay",                                cli_parse_wait, cli_io_handler_wait, cli_release_wait, NULL },
+       { { "wait", NULL },                      "wait {-h|<delay_ms>}                    : wait the specified delay (-h to see usage)",              cli_parse_wait, cli_io_handler_wait, cli_release_wait, NULL },
        {{},}
 }};