script: Rework guile script with new CLI support
Integrate the guile scripting a bit better into the mu cmdline. Rework the old script module for that.
This commit is contained in:
130
lib/mu-script.hh
130
lib/mu-script.hh
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2012-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -16,110 +16,50 @@
|
||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef MU_SCRIPT_HH__
|
||||
#define MU_SCRIPT_HH__
|
||||
|
||||
#include <glib.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/* Opaque structure with information about a script */
|
||||
struct MuScriptInfo;
|
||||
#include <utils/mu-result.hh>
|
||||
|
||||
namespace Mu {
|
||||
|
||||
/**
|
||||
* get the name of the script (sans-extension, if some extension was
|
||||
* provided to mu_script_get_scripts)
|
||||
*
|
||||
* @param msi a MuScriptInfo structure
|
||||
*
|
||||
* @return the name
|
||||
* Information about a script.
|
||||
*
|
||||
*/
|
||||
const char* mu_script_info_name(MuScriptInfo* msi);
|
||||
struct ScriptInfo {
|
||||
std::string name; /**< Name of script */
|
||||
std::string path; /**< Full path to script */
|
||||
std::string oneline; /**< One-line description */
|
||||
std::string description; /**< More help */
|
||||
};
|
||||
|
||||
/**
|
||||
* get the full filesystem path of the script
|
||||
*
|
||||
* @param msi a MuScriptInfo structure
|
||||
*
|
||||
* @return the path
|
||||
/// Sequence of script infos.
|
||||
using ScriptInfos = std::vector<ScriptInfo>;
|
||||
|
||||
/**
|
||||
* Get information about the available scripts
|
||||
*
|
||||
* @return infos
|
||||
*/
|
||||
const char* mu_script_info_path(MuScriptInfo* msi);
|
||||
using ScriptPaths = std::vector<std::string>;
|
||||
ScriptInfos script_infos(const ScriptPaths& paths);
|
||||
|
||||
/**
|
||||
* get a one-line description for the script
|
||||
*
|
||||
* @param msi a MuScriptInfo structure
|
||||
*
|
||||
* @return the description, or NULL if there was none
|
||||
|
||||
/**
|
||||
* Run some specific script
|
||||
*
|
||||
* @param path full path to the scripts
|
||||
* @param args argument vector to pass to the script
|
||||
*
|
||||
* @return Ok() or some error; however, note that this does not return after succesfully
|
||||
* starting a script.
|
||||
*/
|
||||
const char* mu_script_info_one_line(MuScriptInfo* msi);
|
||||
Result<void> run_script(const std::string& path, const std::vector<std::string>& args);
|
||||
|
||||
/**
|
||||
* get a full description for the script
|
||||
*
|
||||
* @param msi a MuScriptInfo structure
|
||||
*
|
||||
* @return the description, or NULL if there was none
|
||||
*/
|
||||
const char* mu_script_info_description(MuScriptInfo* msi);
|
||||
} // namepace Mu
|
||||
|
||||
/**
|
||||
* check whether either the name or one-line description of a
|
||||
* MuScriptInfo matches regular expression rxstr
|
||||
*
|
||||
* @param msi a MuScriptInfo
|
||||
* @param rxstr a regular expression string
|
||||
* @param err receives error information
|
||||
*
|
||||
* @return TRUE if it matches, FALSE if not or in case of error
|
||||
*/
|
||||
gboolean mu_script_info_matches_regex(MuScriptInfo* msi, const char* rxstr, GError** err);
|
||||
|
||||
/**
|
||||
* Get the list of all scripts in path with extension ext
|
||||
*
|
||||
* @param path a file system path
|
||||
* @param ext an extension (e.g., ".scm"), or NULL
|
||||
* @param prefix for the one-line description
|
||||
* (e.g., ";; DESCRIPTION: "), or NULL
|
||||
* @param err receives error information, if any
|
||||
*
|
||||
* @return a list of Mu
|
||||
*/
|
||||
GSList* mu_script_get_script_info_list(const char* path,
|
||||
const char* ext,
|
||||
const char* descprefix,
|
||||
GError** err);
|
||||
|
||||
/**
|
||||
* destroy a list of MuScriptInfo* objects
|
||||
*
|
||||
* @param scriptslst a list of MuScriptInfo* objects
|
||||
*/
|
||||
void mu_script_info_list_destroy(GSList* lst);
|
||||
|
||||
/**
|
||||
* find the MuScriptInfo object for the first script with a certain
|
||||
* name, or return NULL if not found.
|
||||
*
|
||||
* @param lst a list of MuScriptInfo* objects
|
||||
* @param name the name to search for
|
||||
*
|
||||
* @return a MuScriptInfo* object, or NULL if not found.
|
||||
*/
|
||||
MuScriptInfo* mu_script_find_script_with_name(GSList* lst, const char* name);
|
||||
|
||||
/**
|
||||
* run the guile script at path
|
||||
*
|
||||
* @param msi MuScriptInfo object for the script
|
||||
* @param muhome path to the mu home dir
|
||||
* @param args NULL-terminated array of strings (argv for the script)
|
||||
* @param err receives error information
|
||||
*
|
||||
* @return FALSE in case of error -- otherwise, this function will
|
||||
* _not return_
|
||||
*/
|
||||
gboolean
|
||||
mu_script_guile_run(MuScriptInfo* msi, const char* muhome, const char** args, GError** err);
|
||||
|
||||
#endif /*MU_SCRIPT_HH__*/
|
||||
#endif /* MU_SCRIPT_HH__ */
|
||||
|
||||
Reference in New Issue
Block a user