* guile: make running guile scripts a bit more convenient, document it
For example, you can now run a script like:
$ mu msgs-per-month --textonly --query=hello
This commit is contained in:
@ -177,9 +177,9 @@ mu_cmd_script (MuConfig *opts, GError **err)
|
||||
if (err && *err)
|
||||
goto leave;
|
||||
|
||||
if (!opts->script) {
|
||||
if (g_strcmp0 (opts->cmdstr, "script") == 0) {
|
||||
print_scripts (scripts, !opts->nocolor, opts->verbose,
|
||||
opts->params[1], err);
|
||||
opts->script_params[0], err);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
@ -191,8 +191,7 @@ mu_cmd_script (MuConfig *opts, GError **err)
|
||||
}
|
||||
|
||||
/* do it! */
|
||||
mu_script_guile_run (msi, opts->muhome,
|
||||
(const gchar**)&opts->params[1], err);
|
||||
mu_script_guile_run (msi, opts->muhome, opts->script_params, err);
|
||||
leave:
|
||||
/* this won't be reached, unless there is some error */
|
||||
mu_script_info_list_destroy (scripts);
|
||||
|
||||
@ -593,6 +593,8 @@ set_log_options (MuConfig *opts)
|
||||
logopts |= MU_LOG_OPTIONS_DEBUG;
|
||||
}
|
||||
|
||||
|
||||
|
||||
MuError
|
||||
mu_cmd_execute (MuConfig *opts, GError **err)
|
||||
{
|
||||
@ -627,10 +629,7 @@ mu_cmd_execute (MuConfig *opts, GError **err)
|
||||
case MU_CONFIG_CMD_SERVER:
|
||||
merr = with_store (mu_cmd_server, opts, FALSE, err); break;
|
||||
default:
|
||||
show_usage ();
|
||||
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
||||
"unknown command '%s'", opts->cmdstr);
|
||||
return MU_ERROR_IN_PARAMETERS;
|
||||
merr = MU_ERROR_IN_PARAMETERS; break;
|
||||
}
|
||||
|
||||
return merr;
|
||||
|
||||
@ -300,13 +300,14 @@ config_options_group_script (void)
|
||||
{
|
||||
GOptionGroup *og;
|
||||
GOptionEntry entries[] = {
|
||||
{"script", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.script,
|
||||
"script to run (see `mu help script')", "<script>"},
|
||||
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
||||
{G_OPTION_REMAINING, 0,0, G_OPTION_ARG_STRING_ARRAY,
|
||||
&MU_CONFIG.params, "script parameters", NULL},
|
||||
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
og = g_option_group_new("script", "Options for the 'script' command",
|
||||
"", NULL, NULL);
|
||||
|
||||
g_option_group_add_entries(og, entries);
|
||||
|
||||
return og;
|
||||
@ -461,7 +462,7 @@ cmd_from_string (const char *str)
|
||||
{ "index", MU_CONFIG_CMD_INDEX },
|
||||
{ "mkdir", MU_CONFIG_CMD_MKDIR },
|
||||
{ "remove", MU_CONFIG_CMD_REMOVE },
|
||||
{ "script", MU_CONFIG_CMD_SCRIPT },
|
||||
{ "script", MU_CONFIG_CMD_SCRIPT },
|
||||
{ "server", MU_CONFIG_CMD_SERVER },
|
||||
{ "verify", MU_CONFIG_CMD_VERIFY },
|
||||
{ "view", MU_CONFIG_CMD_VIEW }
|
||||
@ -474,7 +475,8 @@ cmd_from_string (const char *str)
|
||||
if (strcmp (str, cmd_map[i].name) == 0)
|
||||
return cmd_map[i].cmd;
|
||||
|
||||
return MU_CONFIG_CMD_UNKNOWN;
|
||||
/* if we don't recognize it, it may be some script */
|
||||
return MU_CONFIG_CMD_SCRIPT;
|
||||
}
|
||||
|
||||
|
||||
@ -673,6 +675,17 @@ parse_params (int *argcp, char ***argvp, GError **err)
|
||||
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)
|
||||
|
||||
@ -183,6 +183,7 @@ struct _MuConfig {
|
||||
* (open) the attmnt using xdgopen */
|
||||
/* options for mu-script */
|
||||
gchar *script; /* script to run */
|
||||
const char **script_params; /* parameters for scripts */
|
||||
};
|
||||
typedef struct _MuConfig MuConfig;
|
||||
|
||||
|
||||
@ -142,25 +142,21 @@ mu4e e-mail client.
|
||||
|
||||
#BEGIN MU_CONFIG_CMD_SCRIPT
|
||||
#STRING
|
||||
mu script [--script=<script>] [<pattern>] [-v] -- [script-options]
|
||||
mu script [<pattern>] [-v]
|
||||
mu <script-name> [<script options>]
|
||||
#STRING
|
||||
Without any parameter, list the available scripts. With <pattern>,
|
||||
list only those scripts whose name or one-line description matches it.
|
||||
With -v, give longer descriptions of each script.
|
||||
|
||||
With --script=<script>, run the script whose name is <script>; pass
|
||||
any arguments to the script after the '--' double-dash.
|
||||
List the available scripts and/or run them (if mu was built with support for
|
||||
scripts). With <pattern>, list only those scripts whose name or one-line
|
||||
description matches it. With -v, get a longer description for each script.
|
||||
|
||||
Some examples:
|
||||
List all available scripts (one-line descriptions):
|
||||
$ mu script
|
||||
|
||||
List all available scripts matching 'month' (long descriptions):
|
||||
$ mu script -v month
|
||||
|
||||
Run the 'msgs-per-month' script, and pass it the '--textonly' parameter:
|
||||
$ mu script --script=msgs-per-month -- --textonly
|
||||
(as mentioned, parameters to the script follow the '--')
|
||||
$ mu msgs-per-month --textonly
|
||||
#END
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user