]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
print_category: print help descriptions aligned
authorDaniel Stenberg <daniel@haxx.se>
Wed, 29 Sep 2021 10:43:09 +0000 (12:43 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 1 Oct 2021 06:35:59 +0000 (08:35 +0200)
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
tests/data/test1461
tests/data/test1463
tests/data/test1464

index 8eee606b76f7ae7d4201e1695ad20f49ca1157a8..d4c21ff6e3d4d8612fa381be385dfa2852e7a756 100644 (file)
@@ -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);
     }
 }
 
index 301dc144e4d01844fa0ff31beeef20dcdf6b2708..847f8d1fb68f4ca6c22751611db8244d655b0d88 100644 (file)
@@ -32,18 +32,18 @@ curl important --help
 </errorcode>
 <stdout mode="text">
 Usage: curl [options...] <url>
- -d, --data <data>   HTTP POST data
- -f, --fail          Fail silently (no output at all) on HTTP errors
- -h, --help <category>  Get help for commands
- -i, --include       Include protocol response headers in the output
- -o, --output <file>  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 <file>  Transfer local FILE to destination
- -u, --user <user:password>  Server user and password
- -A, --user-agent <name>  Send User-Agent <name> to server
- -v, --verbose       Make the operation more talkative
- -V, --version       Show version number and quit
+ -d, --data <data>          HTTP POST data
+ -f, --fail                 Fail silently (no output at all) on HTTP errors
+ -h, --help <category>      Get help for commands
+ -i, --include              Include protocol response headers in the output
+ -o, --output <file>        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 <file>   Transfer local FILE to destination
+ -u, --user <user:password> Server user and password
+ -A, --user-agent <name>    Send User-Agent <name> 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.
index 87a2d3ca2833fca97ea2f9bc621e0b6979c198c0..3904324c7e5653c9dfa0e474cf4a28d4a356b15d 100644 (file)
@@ -37,9 +37,9 @@ curl file category --help
 <stdout mode="text">
 Usage: curl [options...] <url>
 file: FILE protocol options
-     --create-file-mode <mode>  File mode for created files
- -I, --head          Show document info only
- -r, --range <range>  Retrieve only the bytes within RANGE
+     --create-file-mode <mode> File mode for created files
+ -I, --head                    Show document info only
+ -r, --range <range>           Retrieve only the bytes within RANGE
 </stdout>
 </verify>
 </testcase>
index 9821f097b8690b948f46c4f38253b1d45b9509e3..44a7adcf0bf539340760de4a242ebd465f9110ac 100644 (file)
@@ -37,9 +37,9 @@ curl file category --help with lower/upper mix
 <stdout mode="text">
 Usage: curl [options...] <url>
 file: FILE protocol options
-     --create-file-mode <mode>  File mode for created files
- -I, --head          Show document info only
- -r, --range <range>  Retrieve only the bytes within RANGE
+     --create-file-mode <mode> File mode for created files
+ -I, --head                    Show document info only
+ -r, --range <range>           Retrieve only the bytes within RANGE
 </stdout>
 </verify>
 </testcase>