From: Tobias Brunner Date: Thu, 22 May 2025 12:56:24 +0000 (+0200) Subject: swanctl: Reduce indentation in usage output and print command descriptions X-Git-Tag: 6.0.2dr1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f4988eb7c2a1039b8e89c47d400f635e2cfa5a6;p=thirdparty%2Fstrongswan.git swanctl: Reduce indentation in usage output and print command descriptions Also print error message at the end of the output. --- diff --git a/src/swanctl/command.c b/src/swanctl/command.c index 52884ca171..7e654b8751 100644 --- a/src/swanctl/command.c +++ b/src/swanctl/command.c @@ -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; }