pki: Add support to encode public keys in SSH key format
[strongswan.git] / src / pki / command.c
index 246ddfe..984da59 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdio.h>
 
 #include <library.h>
-#include <debug.h>
+#include <utils/debug.h>
 #include <utils/optionsfrom.h>
 
 /**
@@ -144,7 +144,7 @@ void command_register(command_t command)
        /* append default options, but not to --help */
        if (!active)
        {
-               for (i = 0; i < countof(cmds[registered].options); i++)
+               for (i = 0; i < countof(cmds[registered].options) - 1; i++)
                {
                        if (cmds[registered].options[i].name)
                        {
@@ -168,7 +168,6 @@ void command_register(command_t command)
 int command_usage(char *error)
 {
        FILE *out = stdout;
-       char buf[64];
        int i;
 
        if (error)
@@ -177,13 +176,20 @@ int command_usage(char *error)
                fprintf(out, "Error: %s\n", error);
        }
        fprintf(out, "strongSwan %s PKI tool\n", VERSION);
+
+       if (active == help_idx)
+       {
+               fprintf(out, "loaded plugins: %s\n",
+                               lib->plugins->loaded_plugins(lib->plugins));
+       }
+
        fprintf(out, "usage:\n");
        if (active == help_idx)
        {
                for (i = 0; cmds[i].cmd; i++)
                {
-                       snprintf(buf, sizeof(buf), "--%s (-%c)", cmds[i].cmd, cmds[i].op);
-                       fprintf(out, "  pki %-14s %s\n", buf, cmds[i].description);
+                       fprintf(out, "  pki --%-7s (-%c)  %s\n",
+                                       cmds[i].cmd, cmds[i].op, cmds[i].description);
                }
        }
        else
@@ -202,10 +208,9 @@ int command_usage(char *error)
                }
                for (i = 0; cmds[active].options[i].name; i++)
                {
-                       snprintf(buf, sizeof(buf), "--%s (-%c)",
-                                        cmds[active].options[i].name, cmds[active].options[i].op);
-                       fprintf(out, "        %-15s %s\n",
-                                       buf, cmds[active].options[i].desc);
+                       fprintf(out, "        --%-15s (-%c)  %s\n",
+                                       cmds[active].options[i].name, cmds[active].options[i].op,
+                                       cmds[active].options[i].desc);
                }
        }
        return error != NULL;
@@ -253,6 +258,6 @@ int command_dispatch(int c, char *v[])
                        return cmds[i].call();
                }
        }
-       return command_usage("invalid operation");
+       return command_usage(c > 1 ? "invalid operation" : NULL);
 }