poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/3] make .help print the top level commands


From: Jose E. Marchesi
Subject: Re: [PATCH 2/3] make .help print the top level commands
Date: Tue, 01 Oct 2019 15:14:26 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

    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.

Very nice, this is definitely an improvement :)

For commands written in Poke, like `dump', we will want to write an
extensible help system in Poke, supporting docstrings, apropos, and
similar functionality.

Find a few comments below.
    
    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[] =

It would be better to use a less generic name for this now global
symbol.  What about pk_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[];

Likewise.

    +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"));

Hm, what about commands not taking any number of arguments?

    +
    +  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};



reply via email to

[Prev in Thread] Current Thread [Next in Thread]