charon-cmd: Use fixed number of character to align command descriptions
If the command and argument is longer than that write the first line of description to the following line.
This commit is contained in:
1 parent
5e185047e1
commit
5991f09565
1 file changed
+15
-16
+15
-16
@@ -204,15 +204,9 @@ static void segv_handler(int signal)
|
||||
*/
|
||||
static void usage(FILE *out, char *msg, char *binary)
|
||||
{
|
||||
char *pre, *post;
|
||||
int i, line, padto = 0, spacing = 2;
|
||||
|
||||
for (i = 0; i < CMD_OPT_COUNT; i++)
|
||||
{
|
||||
padto = max(padto, strlen(cmd_options[i].name) +
|
||||
strlen(cmd_options[i].arg));
|
||||
}
|
||||
padto += spacing;
|
||||
static const int padto = 18;
|
||||
char cmd[64], *pre, *post;
|
||||
int i, line, pad;
|
||||
|
||||
if (msg)
|
||||
{
|
||||
@@ -237,17 +231,22 @@ static void usage(FILE *out, char *msg, char *binary)
|
||||
post = " ";
|
||||
break;
|
||||
}
|
||||
fprintf(out, " --%s%s%s%s %-*s%s\n",
|
||||
cmd_options[i].name,
|
||||
pre, cmd_options[i].arg, post,
|
||||
padto - strlen(cmd_options[i].name) - strlen(cmd_options[i].arg), "",
|
||||
cmd_options[i].desc);
|
||||
snprintf(cmd, sizeof(cmd), " --%s%s%s%s", cmd_options[i].name,
|
||||
pre, cmd_options[i].arg, post);
|
||||
pad = padto - strlen(cmd);
|
||||
if (pad >= 1)
|
||||
{
|
||||
fprintf(out, "%s%-*s%s\n", cmd, pad, "", cmd_options[i].desc);
|
||||
}
|
||||
else
|
||||
{ /* write description to a separate line */
|
||||
fprintf(out, "%s\n%-*s%s\n", cmd, padto, "", cmd_options[i].desc);
|
||||
}
|
||||
for (line = 0; line < countof(cmd_options[i].lines); line++)
|
||||
{
|
||||
if (cmd_options[i].lines[line])
|
||||
{
|
||||
fprintf(out, "%-*s %s\n",
|
||||
padto, "", cmd_options[i].lines[line]);
|
||||
fprintf(out, "%-*s%s\n", padto, "", cmd_options[i].lines[line]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user