help: comando exibe ajuda curta dos comandos.
[cascardo/declara.git] / lib / help.c
index 66573ba..3a012b4 100644 (file)
 #include "cmd.h"
 #include "util.h"
 
-static const char *helpdir = "help";
+#ifndef DOCDIR
+#define DOCDIR "help"
+#endif
+
+static const char *helpdir = DOCDIR;
+
+static int help_cmds(struct declaracao *dec)
+{
+       void *iter = NULL;
+       struct cmd *cmd;
+       printf("\n");
+       while ((cmd = cmd_next(&iter)) != NULL) {
+               printf("%s - ", cmd->name);
+               if (cmd->help)
+                       printf("%s", cmd->help);
+               printf("\n");
+       }
+       printf("\n");
+}
 
 static int run_help(struct declaracao *dec, char **args, int argc)
 {
@@ -34,7 +52,7 @@ static int run_help(struct declaracao *dec, char **args, int argc)
        char *filename;
        char *basename;
        if (argc == 1)
-               basename = "help";
+               return help_cmds(dec);
        else if (argc == 2)
                basename = args[1];
        else