diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-04 11:38:48 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-04 11:38:48 +0100 |
commit | b70e51fe3c4bd225ad9815b3660e663e9f3766ec (patch) | |
tree | 82f32add17df0af52b613d0f43b3ce8146f6f5eb /eurephiadm | |
parent | 50b32828f5a6dad74c389fd8545b9513791c9e94 (diff) | |
download | eurephia-b70e51fe3c4bd225ad9815b3660e663e9f3766ec.tar.gz eurephia-b70e51fe3c4bd225ad9815b3660e663e9f3766ec.tar.xz eurephia-b70e51fe3c4bd225ad9815b3660e663e9f3766ec.zip |
Improved help functionality
Now each command can (should!) add a help function. This
is done by editing commands.h to add the function name for
the function printing out the help text.
Added help text for the config command.
This help function will be called when eurephiadm is called with:
eurephiadm -h <command>
eurephiadm --help <command>
eurephiadm help <command>
In addition the command function should also parse arguments and
call the help function when --help or -h argument is given, like
eurephiadm config -h
eurephaidm config --help
Diffstat (limited to 'eurephiadm')
-rw-r--r-- | eurephiadm/commands.h | 8 | ||||
-rw-r--r-- | eurephiadm/commands/edit_config.c | 22 | ||||
-rw-r--r-- | eurephiadm/eurephiadm.c | 15 |
3 files changed, 42 insertions, 3 deletions
diff --git a/eurephiadm/commands.h b/eurephiadm/commands.h index a8bafe5..95ae9cf 100644 --- a/eurephiadm/commands.h +++ b/eurephiadm/commands.h @@ -30,7 +30,7 @@ typedef struct { char *accesslvl; char *arghint; char *helpinfo; - char *helpdescr; + void (*helpfunc)(void); int (*function)(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *, int argc, char **argv); } eurephiadm_functions; @@ -40,8 +40,10 @@ int cmd_Logout(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, int cmd_ShowCfg(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv); -/* Commands listed are found in ./commands/{command}.c files - one file per command*/ +/* Commands and help functions listed here are found in ./commands/{command}.c files - one file per command*/ int cmd_ListUsers(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv); + +void help_EditConfig(); int cmd_EditConfig(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv); @@ -66,7 +68,7 @@ static const eurephiadm_functions cmdline_functions[] = { "List only config file settings", NULL, cmd_ShowCfg}, {"config", 1, "config", "[-s|-d] <key>", - "Add, delete or show one config setting", NULL, cmd_EditConfig}, + "Add, delete or show one config setting", help_EditConfig, cmd_EditConfig}, // End of records marker {NULL, 0, NULL, NULL, diff --git a/eurephiadm/commands/edit_config.c b/eurephiadm/commands/edit_config.c index 94865a6..2cfd129 100644 --- a/eurephiadm/commands/edit_config.c +++ b/eurephiadm/commands/edit_config.c @@ -35,11 +35,30 @@ #define MODULE "eurephiadm::config" #include "../argparser.h" +void help_EditConfig() { + printf("%s - Edit eurephia configuration\n\n", MODULE); + printf(" The config command let you add, change or delete\n" + " configuration parameters in the eurephia database\n" + " in an easy way. To be allowed to do so, you must\n" + " have been granted 'config' access.\n\n"); + + printf(" The following arguments are accepted:\n" + " -s | --set <key> <value> Add/change a parameter.\n" + " -D | --delete <key> Remove the parameter.\n" + "\n" + " If no arguments is given, you can give a key name, and the\n" + " associated value will be printed.\n\n" + " eurephiadm config <key>\n\n"); + + printf(" The command will exit with exit code 0 on success.\n\n"); +} + int cmd_EditConfig(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { int rc = 0, i = 0; e_options editargs[] = { {"--set", "-s", 2}, {"--delete", "-D", 1}, + {"--help", "-h", 0}, {NULL, NULL, 0} }; @@ -60,6 +79,9 @@ int cmd_EditConfig(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, rc = eDBadminConfigDelete(ctx, optargs[0]); break; + case 'h': + help_EditConfig(); + default: return 1; } diff --git a/eurephiadm/eurephiadm.c b/eurephiadm/eurephiadm.c index 103c03d..f6ec832 100644 --- a/eurephiadm/eurephiadm.c +++ b/eurephiadm/eurephiadm.c @@ -57,6 +57,21 @@ int cmd_Help(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int a int i; char *prg = NULL; + // Print the modules help screen if it is given + if( argc > 1 ) { + char *help = (strlen_nullsafe(argv[2]) > 0 ? argv[2] : argv[1]); + + for( i = 0; cmdline_functions[i].command != NULL; i++ ) { + func = (eurephiadm_functions *)&cmdline_functions[i]; + if( (strcmp(func->command, help) == 0) && (func->helpfunc != NULL) ) { + func->helpfunc(); + return 0; + } + } + fprintf(stderr, "%s: ERROR :: Could not find help for module '%s'\n", MODULE , help); + return 1; + } + prg = print_version(argv[0]); fprintf(stdout, "\n Usage: %s [global options] <command> [command options]\n\n", prg); |