]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
swanctl: Reduce indentation in usage output and print command descriptions
authorTobias Brunner <tobias@strongswan.org>
Thu, 22 May 2025 12:56:24 +0000 (14:56 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 27 May 2025 15:38:24 +0000 (17:38 +0200)
Also print error message at the end of the output.

src/swanctl/command.c

index 52884ca171c994d63cb9319f86c0b634dad9f886..7e654b875141787a97e915d1fb9b2b49eb5da161 100644 (file)
@@ -211,31 +211,24 @@ int command_usage(char *error, ...)
        if (error)
        {
                out = stderr;
-               fprintf(out, "Error: ");
-               va_start(args, error);
-               vfprintf(out, error, args);
-               va_end(args);
-               fprintf(out, "\n");
        }
-       fprintf(out, "strongSwan %s swanctl\n", VERSION);
+       fprintf(out, "strongSwan %s swanctl", VERSION);
 
        if (active == help_idx)
        {
-               fprintf(out, "loaded plugins: %s\n",
+               fprintf(out, "\nloaded plugins: %s\nusage:\n"
+                               "  swanctl command [options]\ncommands:\n",
                                lib->plugins->loaded_plugins(lib->plugins));
-       }
-
-       fprintf(out, "usage:\n");
-       if (active == help_idx)
-       {
                for (i = 0; i < MAX_COMMANDS && cmds[i].cmd; i++)
                {
-                       fprintf(out, "  swanctl --%-16s (-%c)  %s\n",
+                       fprintf(out, "  --%-16s (-%c)  %s\n",
                                        cmds[i].cmd, cmds[i].op, cmds[i].description);
                }
        }
        else
        {
+               fprintf(out, " (--%s/-%c)\n%s\nusage:\n",
+                               cmds[active].cmd, cmds[active].op, cmds[active].description);
                for (i = 0; i < MAX_LINES && cmds[active].line[i]; i++)
                {
                        if (i == 0)
@@ -245,16 +238,25 @@ int command_usage(char *error, ...)
                        }
                        else
                        {
-                               fprintf(out, "                 %s\n", cmds[active].line[i]);
+                               fprintf(out, "    %s\n", cmds[active].line[i]);
                        }
                }
+               fprintf(out, "options:\n");
                for (i = 0; cmds[active].options[i].name; i++)
                {
-                       fprintf(out, "           --%-15s (-%c)  %s\n",
+                       fprintf(out, "  --%-15s (-%c)  %s\n",
                                        cmds[active].options[i].name, cmds[active].options[i].op,
                                        cmds[active].options[i].desc);
                }
        }
+       if (error)
+       {
+               fprintf(out, "error: ");
+               va_start(args, error);
+               vfprintf(out, error, args);
+               va_end(args);
+               fprintf(out, "\n");
+       }
        return error != NULL;
 }