[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] make .help print the top level commands
From: |
Oliver O'Halloran |
Subject: |
[PATCH 2/3] make .help print the top level commands |
Date: |
Sun, 29 Sep 2019 23:51:18 +1000 |
Currently when you launch poke you get:
For help, type ".help".
Type ".exit" to leave the program.
(poke) .help
Usage: help COMMAND
(poke)
Which is not terribly helpful. Making .help list the top level commands
at least gives you a way to explore further. With this patch applied
you get:
(poke) .help
top level commands:
.file
.exit
.version
.info
.close
.load
.help
.vm
.print[/xobm]
.set
Run a command without arguments to see its sub-commands
(poke)
I'm not sure this is the best thing to do long term since we'll probably
want .help to have actual subcommands eventually.
Signed-off-by: Oliver O'Halloran <address@hidden>
---
src/pk-cmd.c | 8 +++++---
src/pk-help.c | 20 +++++++++++++++++++-
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/src/pk-cmd.c b/src/pk-cmd.c
index 31b990c..7500471 100644
--- a/src/pk-cmd.c
+++ b/src/pk-cmd.c
@@ -54,7 +54,7 @@ extern struct pk_cmd set_cmd; /* pk-set.c */
struct pk_cmd null_cmd =
{NULL, NULL, NULL, 0, NULL, NULL};
-static struct pk_cmd *cmds[] =
+struct pk_cmd *cmds[] =
{
&file_cmd,
&exit_cmd,
@@ -308,9 +308,11 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char
*prefix)
if (cmd->subtrie != NULL)
{
p = skip_blanks (p);
- if (*p == '\0')
+ if (*p == '\0' && !cmd->handler)
goto usage;
- return pk_cmd_exec_1 (p, *cmd->subtrie, cmd_name);
+
+ if (*p != '\0')
+ return pk_cmd_exec_1 (p, *cmd->subtrie, cmd_name);
}
/* Parse arguments. */
diff --git a/src/pk-help.c b/src/pk-help.c
index 54d018e..622c3ac 100644
--- a/src/pk-help.c
+++ b/src/pk-help.c
@@ -17,9 +17,27 @@
*/
#include <config.h>
+#include <gettext.h>
+#define _(str) dgettext (PACKAGE, str)
#include "pk-cmd.h"
extern struct pk_cmd null_cmd; /* pk-cmd.c */
+extern struct pk_cmd *cmds[];
+
+static int
+list_cmds_fn (int argc, struct pk_cmd_arg argv[], uint64_t uflags)
+{
+ struct pk_cmd **c;
+
+ printf (_("top level commands:\n"));
+ for (c = cmds; *c != &null_cmd; c++) {
+ printf(_(" .%s\n"), (*c)->name);
+ }
+
+ printf (_("Run a command without arguments to see its sub-commands\n"));
+
+ return 0;
+}
struct pk_cmd *help_cmds[] =
{
@@ -29,4 +47,4 @@ struct pk_cmd *help_cmds[] =
struct pk_trie *help_trie;
struct pk_cmd help_cmd =
- {"help", "", "", 0, help_cmds, NULL, "help COMMAND", &help_trie};
+ {"help", "", "", 0, help_cmds, list_cmds_fn, "help", &help_trie};
--
2.21.0