pki: Reduce indentation in usage output and print command description
Also print error message at the end of the output.
This commit is contained in:
+15
-13
@@ -213,44 +213,42 @@ void command_register(command_t command)
|
||||
int command_usage(char *error)
|
||||
{
|
||||
FILE *out = stdout;
|
||||
int i, indent = 0;
|
||||
int i;
|
||||
|
||||
if (error)
|
||||
{
|
||||
out = stderr;
|
||||
fprintf(out, "Error: %s\n", error);
|
||||
}
|
||||
fprintf(out, "strongSwan %s PKI tool\n", VERSION);
|
||||
fprintf(out, "strongSwan %s PKI tool", VERSION);
|
||||
|
||||
if (active == help_idx)
|
||||
{
|
||||
fprintf(out, "loaded plugins: %s\n",
|
||||
fprintf(out, "\nloaded plugins: %s\nusage:\n"
|
||||
" pki 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, " pki --%-7s (-%c) %s\n",
|
||||
fprintf(out, " --%-7s (-%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)
|
||||
{
|
||||
indent = fprintf(out, " pki --%s ", cmds[active].cmd);
|
||||
fprintf(out, "%s\n", cmds[active].line[i]);
|
||||
fprintf(out, " pki --%s %s\n", cmds[active].cmd,
|
||||
cmds[active].line[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(out, "%*s%s\n", indent, "", 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",
|
||||
@@ -258,6 +256,10 @@ int command_usage(char *error)
|
||||
cmds[active].options[i].desc);
|
||||
}
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
fprintf(out, "error: %s\n", error);
|
||||
}
|
||||
return error != NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -631,9 +631,9 @@ static void __attribute__ ((constructor))reg()
|
||||
scep, 'S', "scep",
|
||||
"Enroll an X.509 certificate with a SCEP server",
|
||||
{"--url url [--in file] [--dn distinguished-name] [--san subjectAltName]+",
|
||||
"[--profile profile] [--password password]",
|
||||
"--cacert-enc file --cacert-sig file [--cacert file]+",
|
||||
" --cert file --key file] [--cipher aes|des3]",
|
||||
"[--profile profile] [--password password]",
|
||||
"[--cert file --key file] [--cipher aes|des3]",
|
||||
"[--digest sha256|sha384|sha512|sha224|sha1] [--rsa-padding pkcs1|pss]",
|
||||
"[--interval time] [--maxpolltime time] [--outform der|pem]"},
|
||||
{
|
||||
@@ -646,9 +646,9 @@ static void __attribute__ ((constructor))reg()
|
||||
{"password", 'p', 1, "challengePassword to include in cert request"},
|
||||
{"cacert-enc", 'e', 1, "CA certificate for encryption"},
|
||||
{"cacert-sig", 's', 1, "CA certificate for signature verification"},
|
||||
{"cacert", 'C', 1, "Additional CA certificates"},
|
||||
{"cert", 'c', 1, "Old certificate about to be renewed"},
|
||||
{"key", 'k', 1, "Old RSA private key about to be replaced"},
|
||||
{"cacert", 'C', 1, "additional CA certificates"},
|
||||
{"cert", 'c', 1, "old certificate about to be renewed"},
|
||||
{"key", 'k', 1, "old RSA private key about to be replaced"},
|
||||
{"cipher", 'E', 1, "encryption cipher, default: aes"},
|
||||
{"digest", 'g', 1, "digest for signature creation, default: sha256"},
|
||||
{"rsa-padding", 'R', 1, "padding for RSA signatures, default: pkcs1"},
|
||||
|
||||
@@ -256,12 +256,12 @@ static void __attribute__ ((constructor))reg()
|
||||
{
|
||||
command_register((command_t) {
|
||||
verify, 'v', "verify",
|
||||
"verify a certificate using the CA certificate",
|
||||
{"[--in file] [--cacert file] [--crl file]"},
|
||||
"verify a certificate using one or more CA certificates",
|
||||
{"[--in file] [--cacert file]+ [--crl file]"},
|
||||
{
|
||||
{"help", 'h', 0, "show usage information"},
|
||||
{"in", 'i', 1, "X.509 certificate to verify, default: stdin"},
|
||||
{"cacert", 'c', 1, "CA certificate for trustchain verification"},
|
||||
{"cacert", 'c', 1, "CA certificate(s) for trustchain verification"},
|
||||
{"crl", 'l', 1, "CRL for trustchain verification"},
|
||||
{"online", 'o', 0, "enable online CRL/OCSP revocation checking"},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user