static gboolean parse_params (int *argcp, char ***argvp) { GError *err; GOptionContext *context; gboolean rv; context = g_option_context_new("- mu general options"); g_option_context_set_main_group(context, config_options_group_mu()); g_option_context_set_help_enabled (context, TRUE); err = NULL; /* help is special */ if (MU_CONFIG.cmd == MU_CONFIG_CMD_HELP) { rv = g_option_context_parse (context, argcp, argvp, &err) && init_cmd_help (&err); } else { GOptionGroup *group; group = get_option_group (MU_CONFIG.cmd); if (group) g_option_context_add_group(context, group); rv = g_option_context_parse (context, argcp, argvp, &err); } g_option_context_free (context); if (!rv) { g_printerr ("mu: error in options: %s\n", err ? err->message : "?"); g_clear_error (&err); return FALSE; } return TRUE; }
static gboolean parse_params (int *argcp, char ***argvp, GError **err) { GOptionContext *context; GOptionGroup *group; gboolean rv; context = g_option_context_new("- mu general options"); g_option_context_set_help_enabled (context, TRUE); err = NULL; rv = TRUE; g_option_context_set_main_group(context, config_options_group_mu()); switch (MU_CONFIG.cmd) { case MU_CONFIG_CMD_NONE: show_usage(); break; case MU_CONFIG_CMD_HELP: /* 'help' is special; sucks in the options of the * command after it */ rv = g_option_context_parse (context, argcp, argvp, err) && cmd_help (); break; default: group = get_option_group (MU_CONFIG.cmd); if (group) g_option_context_add_group(context, group); rv = g_option_context_parse (context, argcp, argvp, err); } g_option_context_free (context); return rv ? TRUE : FALSE; }
void mu_config_show_help (MuConfigCmd cmd) { GOptionContext *ctx; GOptionGroup *group; char *cleanhelp; g_return_if_fail (mu_config_cmd_is_valid(cmd)); ctx = g_option_context_new (""); g_option_context_set_main_group (ctx, config_options_group_mu()); group = get_option_group (cmd); if (group) g_option_context_add_group (ctx, group); g_option_context_set_description (ctx, get_help_string (cmd, TRUE)); cleanhelp = massage_help (g_option_context_get_help (ctx, TRUE, group)); g_print ("usage:\n\t%s\n%s", get_help_string (cmd, FALSE), cleanhelp); g_free (cleanhelp); }
static gboolean parse_params (int *argcp, char ***argvp, GError **err) { GOptionContext *context; GOptionGroup *group; gboolean rv; context = g_option_context_new("- mu general options"); g_option_context_set_help_enabled (context, TRUE); rv = TRUE; g_option_context_set_main_group(context, config_options_group_mu()); g_option_context_set_ignore_unknown_options (context, FALSE); switch (MU_CONFIG.cmd) { case MU_CONFIG_CMD_NONE: show_usage(); break; case MU_CONFIG_CMD_HELP: /* 'help' is special; sucks in the options of the * command after it */ rv = g_option_context_parse (context, argcp, argvp, err) && cmd_help (); break; case MU_CONFIG_CMD_SCRIPT: /* all unknown commands are passed to 'script' */ g_option_context_set_ignore_unknown_options (context, TRUE); group = get_option_group (MU_CONFIG.cmd); g_option_context_add_group (context, group); rv = g_option_context_parse (context, argcp, argvp, err); MU_CONFIG.script = g_strdup (MU_CONFIG.cmdstr); /* argvp contains the script parameters */ MU_CONFIG.script_params = (const char**)&((*argvp)[1]); break; default: group = get_option_group (MU_CONFIG.cmd); if (group) g_option_context_add_group (context, group); rv = g_option_context_parse (context, argcp, argvp, err); break; } g_option_context_free (context); return rv ? TRUE : FALSE; }
static gboolean init_cmd_help (GError **err) { MuConfigCmd cmd; GOptionContext *ctx; GOptionGroup *group; char *cleanhelp; if (!MU_CONFIG.params || !MU_CONFIG.params[0] || !MU_CONFIG.params[1] || MU_CONFIG.params[2]) goto errexit; cmd = cmd_from_string (MU_CONFIG.params[1]); if (cmd == MU_CONFIG_CMD_UNKNOWN) goto errexit; ctx = g_option_context_new (""); g_option_context_set_main_group (ctx, config_options_group_mu()); group = get_option_group (cmd); if (group) g_option_context_add_group (ctx, group); g_option_context_set_description (ctx, cmd_help (cmd, TRUE)); cleanhelp = massage_help (g_option_context_get_help (ctx, TRUE, group)); g_print ("Usage:\n\t%s\n%s", cmd_help (cmd, FALSE), cleanhelp); g_free (cleanhelp); return TRUE; errexit: mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, "usage: mu help <command>"); return FALSE; }
static gboolean parse_params (MuConfig *opts, int *argcp, char ***argvp) { GError *err = NULL; GOptionContext *context; gboolean rv; context = g_option_context_new("- mu general option"); g_option_context_set_main_group(context, config_options_group_mu(opts)); add_context_group (context, opts); rv = g_option_context_parse (context, argcp, argvp, &err); g_option_context_free (context); if (!rv) { g_printerr ("mu: error in options: %s\n", err->message); g_error_free (err); return FALSE; } return TRUE; }