[Toybox] --help

Rob Landley rob at landley.net
Mon Apr 8 01:54:49 PDT 2013


On 04/05/2013 11:18:52 PM, Isaac Dunham wrote:
> > Is there an acceptable way to standardize this across all toys?
> 
> To some extent, there will be variation.
> But I was looking at ifconfig and found it had an interesting  
> approach:
> static void show_help(void)
> {
>   char **arg = xzalloc(sizeof(char*) *3);
>   arg[0] = "help";
>   arg[1] = xstrdup(toys.which->name);
>   toy_exec(arg);
> }
> ..
>  if(argv[0] && (strcmp(argv[0], "--help") == 0))
>   show_help();
> 
> It seems to me that show_help() might be suitable for inclusion in  
> lib/.

In lib/args.c there's exithelp which is used in lib/lib.c ala:

// Die with an error message.
void error_exit(char *msg, ...)
{
   va_list va;

   if (CFG_HELP && toys.exithelp) {
     *toys.optargs=*toys.argv;
     USE_HELP(help_main();)  // dear gcc: shut up.
     fprintf(stderr,"\n");
   }

Note that CFG_HELP is the help command in the "other" menu. I've  
pondered having that be in the toybox general config menu instead of as  
a command, but since there _is_ a command having two config symbols is  
suboptimal...

This whole area is a todo item, but ifconfig is not taking advantage of  
the existing toybox infrastructure, and thus not a good model here.

> In theory, one could make the main logic handle <toy> --help like  
> help <toy>,
> but it would be impossible to implement POSIX and still support
> help with -h in all cases where it's appropriate (I remember one or  
> two commands
> use -h for other purposes, though I don't remember which).

Right now it shows help for any unknown argument. So "-?" should do it  
too (assuming that doesn't wildcard match something weird).

> Of course the
> char **argv = toys.optargs;
> looks rather ugly to me...

The whole of ifconfig needs more cleanup. It's on the todo list...

Rob

 1365411289.0


More information about the Toybox mailing list