From f1114892dfd4da20eab436cfbb979f55c40512c0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Sep 2021 12:43:09 +0200 Subject: print_category: print help descriptions aligned Adjust the description position to make an aligned column when doing help listings, which is more pleasing to the eye. Suggested-by: Gisle Vanem Closes #7792 --- src/tool_help.c | 19 ++++++++++++++++++- tests/data/test1461 | 24 ++++++++++++------------ tests/data/test1463 | 6 +++--- tests/data/test1464 | 6 +++--- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/tool_help.c b/src/tool_help.c index 8eee606b7..d4c21ff6e 100644 --- a/src/tool_help.c +++ b/src/tool_help.c @@ -115,9 +115,26 @@ static const struct feat feats[] = { static void print_category(curlhelp_t category) { unsigned int i; + size_t longopt = 5; + size_t longdesc = 5; + + for(i = 0; helptext[i].opt; ++i) { + size_t len; + if(!(helptext[i].categories & category)) + continue; + len = strlen(helptext[i].opt); + if(len > longopt) + longopt = len; + len = strlen(helptext[i].desc); + if(len > longdesc) + longdesc = len; + } + if(longopt + longdesc > 80) + longopt = 80 - longdesc; + for(i = 0; helptext[i].opt; ++i) if(helptext[i].categories & category) { - printf(" %-18s %s\n", helptext[i].opt, helptext[i].desc); + printf(" %-*s %s\n", longopt, helptext[i].opt, helptext[i].desc); } } diff --git a/tests/data/test1461 b/tests/data/test1461 index 301dc144e..847f8d1fb 100644 --- a/tests/data/test1461 +++ b/tests/data/test1461 @@ -32,18 +32,18 @@ curl important --help Usage: curl [options...] - -d, --data HTTP POST data - -f, --fail Fail silently (no output at all) on HTTP errors - -h, --help Get help for commands - -i, --include Include protocol response headers in the output - -o, --output Write to file instead of stdout - -O, --remote-name Write output to a file named as the remote file - -s, --silent Silent mode - -T, --upload-file Transfer local FILE to destination - -u, --user Server user and password - -A, --user-agent Send User-Agent to server - -v, --verbose Make the operation more talkative - -V, --version Show version number and quit + -d, --data HTTP POST data + -f, --fail Fail silently (no output at all) on HTTP errors + -h, --help Get help for commands + -i, --include Include protocol response headers in the output + -o, --output Write to file instead of stdout + -O, --remote-name Write output to a file named as the remote file + -s, --silent Silent mode + -T, --upload-file Transfer local FILE to destination + -u, --user Server user and password + -A, --user-agent Send User-Agent to server + -v, --verbose Make the operation more talkative + -V, --version Show version number and quit This is not the full help, this menu is stripped into categories. Use "--help category" to get an overview of all categories. diff --git a/tests/data/test1463 b/tests/data/test1463 index 87a2d3ca2..3904324c7 100644 --- a/tests/data/test1463 +++ b/tests/data/test1463 @@ -37,9 +37,9 @@ curl file category --help Usage: curl [options...] file: FILE protocol options - --create-file-mode File mode for created files - -I, --head Show document info only - -r, --range Retrieve only the bytes within RANGE + --create-file-mode File mode for created files + -I, --head Show document info only + -r, --range Retrieve only the bytes within RANGE diff --git a/tests/data/test1464 b/tests/data/test1464 index 9821f097b..44a7adcf0 100644 --- a/tests/data/test1464 +++ b/tests/data/test1464 @@ -37,9 +37,9 @@ curl file category --help with lower/upper mix Usage: curl [options...] file: FILE protocol options - --create-file-mode File mode for created files - -I, --head Show document info only - -r, --range Retrieve only the bytes within RANGE + --create-file-mode File mode for created files + -I, --head Show document info only + -r, --range Retrieve only the bytes within RANGE -- cgit v1.2.1