From 748ef30f44c934e066a1feab7102c06c88b6515c Mon Sep 17 00:00:00 2001 From: short <> Date: Tue, 28 Oct 2003 14:04:09 +0000 Subject: [PATCH] Support 'help command_name' as the equivalent of 'command_name --help'. Fixed 'command_name --help' to prevent exit of captive-cmdline(1). Fixed 'command_name --help' false complaint. --- src/client/cmdline/main.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/client/cmdline/main.c b/src/client/cmdline/main.c index a8addad..0459c3f 100644 --- a/src/client/cmdline/main.c +++ b/src/client/cmdline/main.c @@ -84,11 +84,32 @@ const struct cmdline_command cmdline_command_table[]={ { "rmdir" ,N_("Remove guest-os directory[1].") ,cmd_rmdir_table ,cmd_rmdir ,1,1 }, { "commit",N_("Write any pending changes and remount the volume.") ,cmd_commit_table,cmd_commit,0,0 }, { "quit" ,N_("Quit this program.") ,cmd_quit_table ,cmd_quit ,0,0 }, - { "help" ,N_("Show this list of commands.") ,cmd_help_table ,cmd_help ,0,0 }, + { "help" ,N_("Show this list of commands or help for command[1].") ,cmd_help_table ,cmd_help ,0,1 }, { NULL }, /* G_N_ELEMENTS() not usable as sizeof() is not visible for 'extern' */ }; +static gboolean displayArgs_hit; + +static void displayArgs(poptContext con,enum poptCallbackReason foo,struct poptOption *key,const char *arg,void *data) +{ + displayArgs_hit=TRUE; + + if (key->shortName=='?') + poptPrintHelp(con,stdout,0); + else + poptPrintUsage(con,stdout,0); +} + +const struct poptOption cmdline_poptHelpOptions[]={ + { argInfo:POPT_ARG_INTL_DOMAIN,arg:"popt" }, + { NULL ,'\0',POPT_ARG_CALLBACK,(void *)&displayArgs,'\0',NULL,NULL }, + { "help" ,'?' ,0 ,NULL,'?',/* N_ */("Show this help message"), NULL }, + { "usage",'\0',0 ,NULL,'u',/* N_ */("Display brief usage message"),NULL }, + POPT_TABLEEND + }; + + static void invoke_cmd_err(int cmd_argc,const char **cmd_argv,GError **errp) { const struct cmdline_command *commandp; @@ -124,6 +145,7 @@ const char *stub_shell[]={ cmdline_command_table[0].name,NULL }; _("Unknown command, try 'help': %s"),cmd_name); return; } + displayArgs_hit=FALSE; cmd_context=poptGetContext( PACKAGE, /* name */ cmd_argc,cmd_argv, /* argc,argv */ @@ -139,16 +161,19 @@ const char *stub_shell[]={ cmdline_command_table[0].name,NULL }; if (errint!=0) { g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_READING_COMMAND_CONFIG, _("Error '%s' reading default configuration for command: %s"),poptStrerror(errint),cmd_name); - return; + goto err_free_context; } errint=poptGetNextOpt(cmd_context); if (errint!=-1) { g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_EXCEEDING_COMMAND_OPTION, _("Exceeding command option for command: %s"),cmd_name); - return; + goto err_free_context; } if (!(cmdarg_argv=poptGetArgs(cmd_context))) cmdarg_argv=&emptyargv_NULL; + + if (displayArgs_hit) + goto err_free_context; for (csp=cmdarg_argv,cmdarg_argc=0;*csp;csp++) cmdarg_argc++; @@ -156,11 +181,12 @@ const char *stub_shell[]={ cmdline_command_table[0].name,NULL }; g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_INVALID_COMMAND_ARGUMENT_COUNT, _("Invalid number of command '%s' arguments: %d; expected from %d to %d incl."), cmd_name,cmdarg_argc,commandp->argsn_min,commandp->argsn_max); - return; + goto err_free_context; } (*commandp->func)(cmdarg_argv,errp); +err_free_context: poptFreeContext(cmd_context); } -- 1.8.3.1