mu: add 'scm' command

Add the "scm" command, the way to get a Guile/Scheme shell.

This is experimental but will replace the current guile support in guile/ at
some point.
This commit is contained in:
Dirk-Jan C. Binnema
2025-05-31 12:41:37 +03:00
parent 7f274fe518
commit f9c24c7166
6 changed files with 73 additions and 6 deletions

View File

@ -288,8 +288,20 @@ topic_mu(const Options& opts)
"yes"
#else
"no"
#endif
, "GNU Guile 3.x scripting support?"});
#endif /*BUILD_GUILE*/
, "GNU Guile 3.x support (old)?"});
info.add_row({"scm-support",
#if BUILD_SCM
"yes"
#else
"no"
#endif /*BUILD_SCM*/
, "GNU Guile 3.x support (new)?"});
info.add_row({"readline-support",
#if HAVE_LIBREADLINE
"yes"

View File

@ -35,6 +35,10 @@
#include "message/mu-message.hh"
#include "message/mu-mime-object.hh"
#if BUILD_GUILE
#include "scm/mu-scm.hh"
#endif/*BUILD_GUILE*/
#include "utils/mu-error.hh"
#include "utils/mu-utils-file.hh"
#include "utils/mu-utils.hh"
@ -43,7 +47,6 @@
using namespace Mu;
static Result<void>
cmd_fields(const Options& opts)
{
@ -63,6 +66,17 @@ cmd_find(const Options& opts)
return mu_cmd_find(*store, opts);
}
static Result<void>
cmd_scm(const Store& store, const Options& opts)
{
#if !BUILD_SCM
return Err(Error::Code::InvalidArgument,
"scm/guile is not available in this build");
#else
return Mu::Scm::run(Mu::Scm::Config{store, opts});
#endif /*BUILD_SCM*/
}
static void
show_usage(void)
@ -133,6 +147,9 @@ Mu::mu_cmd_execute(const Options& opts) try {
return cmd_find(opts);
case Options::SubCommand::Info:
return with_readonly_store(mu_cmd_info, opts);
case Options::SubCommand::Scm:
return with_readonly_store(cmd_scm, opts);
/* writable store */

View File

@ -545,7 +545,15 @@ sub_server(CLI::App& sub, Options& opts)
sub.add_flag("--allow-temp-file", opts.server.allow_temp_file,
"Allow for the temp-file optimization")
->excludes("--commands");
}
static void
sub_scm(CLI::App& sub, Options& opts)
{
sub.add_option("script-path", opts.scm.script_path, "Path to script")
->type_name("<path>");
sub.add_option("script-args", opts.scm.params, "Parameters for script")
->type_name("<parameters>");
}
static void
@ -665,9 +673,13 @@ AssocPairs<SubCommand, CommandInfo, Options::SubCommandNum> SubCommandInfos= {{
{Category::NeedsWritableStore,
"remove", "Remove message from file-system and database", sub_remove }
},
{ SubCommand::Scm,
{Category::None,
"scm", "Start Guile/Scheme shell",sub_scm}
},
{ SubCommand::Script,
// Note: SubCommand::Script is special; there's no literal
// "script" subcommand, there subcommands for all the scripts.
// "script" subcommand, there are subcommands for all the scripts.
{Category::None,
"script", "Invoke a script", {}}
},

View File

@ -40,6 +40,7 @@ struct Options {
using SizeVec = std::vector<std::size_t>;
using OptTStamp = Option<std::time_t>;
using OptFieldId = Option<Field::Id>;
using OptString = Option<std::string>;
using StringVec = std::vector<std::string>;
/*
@ -62,7 +63,7 @@ struct Options {
enum struct SubCommand {
Add, Cfind, Extract, Fields, Find, Help, Index,Info, Init, Mkdir,
Move, Remove, Script, Server, Verify, View,
Move, Remove, Scm, Script, Server, Verify, View,
// <private>
__count__
};
@ -80,6 +81,7 @@ struct Options {
SubCommand::Mkdir,
SubCommand::Move,
SubCommand::Remove,
SubCommand::Scm,
SubCommand::Script,
SubCommand::Server,
SubCommand::Verify,
@ -226,6 +228,16 @@ struct Options {
StringVec files; /**< Files to remove */
} remove;
/*
* Scm
*/
struct Scm {
OptString script_path; /**< Path to script (optional) */
StringVec params; /**< Parameters for script (after "--") */
} scm;
/*
* Scripts (i.e., finding scriot)
*/