From 2ad05fc7a8666fe480d68eb5533430a5ea2a72a7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 16 Feb 2019 08:42:12 +0100 Subject: init: add a new "help" command The "he" or "?" command displays the list of supported commands. This is convenient as some are not always obvious to remember. --- init/init.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/init/init.c b/init/init.c index 906fcbe..e2be674 100644 --- a/init/init.c +++ b/init/init.c @@ -227,6 +227,7 @@ enum { TOK_PO, /* po : power off */ TOK_RB, /* rb : reboot */ TOK_SP, /* sp : suspend */ + TOK_HE, /* he : help */ /* better add new commands above */ TOK_OB, /* { : begin a command block */ TOK_CB, /* } : end a command block */ @@ -284,6 +285,7 @@ static const struct token tokens[] = { "po", 0, 0, /* TOK_PO */ "rb", 0, 0, /* TOK_RB */ "sp", 0, 0, /* TOK_SP */ + "he", '?', 0, /* TOK_HE */ "{", '{', 0, /* TOK_OB */ "}", '}', 0, /* TOK_CB */ ".", '.', 0, /* TOK_DOT : put every command before this one */ @@ -1980,6 +1982,21 @@ int main(int argc, char **argv, char **envp) error = !res || !streq(res, "devtmpfs"); goto finish_cmd; + } else if (token == TOK_HE) { + int i; + /* ? / help : show supported commands */ + println("Supported commands:"); + println("# long short args"); + for (i = 0; i < TOK_OB; i++) { + print(" "); + printn(tokens[i].lcmd, 2); + print(" "); + pchar(tokens[i].scmd ? tokens[i].scmd : '-'); + print(" "); + pchar(tokens[i].minargs + '0'); + pchar('\n'); + } + goto finish_cmd; } /* other options are reserved for pid 1/linuxrc/rebuild and prompt mode */ -- 2.20.1