]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: list categories in --help
authorDan Fandrich <dan@coneharvesters.com>
Fri, 28 Jun 2024 21:41:29 +0000 (14:41 -0700)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 5 Jul 2024 21:09:47 +0000 (23:09 +0200)
This eliminates the need to run an extra help subcommand to get the
possible categories, reducing the friction in getting relevant help. The
help wording was also slightly tweaked for grammatical accuracy.

Closes #14055

src/tool_help.c
tests/data/test1461

index bd231eb14ba817793e50166bbc1f6e28190c332e..a3df3b14b6ac5fadbdf862c2c6f6ae1a307d7f92 100644 (file)
@@ -129,6 +129,33 @@ static void get_categories(void)
     printf(" %-11s %s\n", categories[i].opt, categories[i].desc);
 }
 
+/* Prints all categories as a comma-separated list of given width */
+static void get_categories_list(unsigned int width)
+{
+  unsigned int i;
+  size_t col = 0;
+  for(i = 0; categories[i].opt; ++i) {
+    size_t len = strlen(categories[i].opt);
+    if(!categories[i + 1].opt) {
+      /* final category */
+      if(col + len + 1 < width)
+        printf("%s.\n", categories[i].opt);
+      else
+        /* start a new line first */
+        printf("\n%s.\n", categories[i].opt);
+    }
+    else if(col + len + 2 < width) {
+      printf("%s, ", categories[i].opt);
+      col += len + 2;
+    }
+    else {
+      /* start a new line first */
+      printf("\n%s, ", categories[i].opt);
+      col = len + 2;
+    }
+  }
+}
+
 
 void tool_help(char *category)
 {
@@ -136,12 +163,15 @@ void tool_help(char *category)
   puts("Usage: curl [options...] <url>");
   /* If no category was provided */
   if(!category) {
-    const char *category_note = "\nThis is not the full help, this "
-      "menu is stripped into categories.\nUse \"--help category\" to get "
-      "an overview of all categories.\nFor all options use the manual"
+    const char *category_note = "\nThis is not the full help; this "
+      "menu is split into categories.\nUse \"--help category\" to get "
+      "an overview of all categories, which are:";
+    const char *category_note2 = "For all options use the manual"
       " or \"--help all\".";
     print_category(CURLHELP_IMPORTANT, cols);
     puts(category_note);
+    get_categories_list(cols);
+    puts(category_note2);
   }
   /* Lets print everything if "all" was provided */
   else if(curl_strequal(category, "all"))
index 424af943fc9292d84c79eb2c05ed02f1916040f5..e9a93b5a979a8bc342288b319ab9acacd1f25b73 100644 (file)
@@ -45,8 +45,10 @@ Usage: curl [options...] <url>
  -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.
+This is not the full help; this menu is split into categories.
+Use "--help category" to get an overview of all categories, which are:
+auth, connection, curl, dns, file, ftp, http, imap, misc, output, pop3, post, 
+proxy, scp, sftp, smtp, ssh, telnet, tftp, tls, ech, upload, verbose.
 For all options use the manual or "--help all".
 </stdout>
 </verify>