![]() |
MaCh3
2.6.1
Reference Guide
|
Main program class that manages modules, plugins, and command-line parsing. More...
#include <CLI/MaCh3Program.hpp>
Public Member Functions | |
| virtual | ~MaCh3Program () |
| Destructor that unloads all dynamic plugins. More... | |
| void | add_core_module (IModule &module) |
| Add a core module to the program. More... | |
| void | load_dynamic_plugins () |
| Load dynamic plugins from the MACH3_PLUGINS environment variable. More... | |
| void | install_completions () const |
| Install shell completion scripts for bash and zsh. More... | |
| void | completions (const std::string &prefix) const |
| Generate completion suggestions for the given prefix. More... | |
| void | unload_dynamic_plugins () |
| Unload all dynamically loaded plugins. More... | |
| int | Run () |
| Run the selected subcommand. More... | |
Public Member Functions inherited from M3::MaCh3ArgumentParser | |
| virtual | ~MaCh3ArgumentParser ()=default |
| const std::string | name () const |
| Get the name of this parser/subcommand. More... | |
| const std::list< std::reference_wrapper< ArgumentParser > > & | subparsers () const |
| Get the list of registered subparsers. More... | |
| const MaCh3ArgumentParser & | get_subcommand_used () const |
| Get the subcommand that was used in parsing. More... | |
Private Member Functions | |
| std::string | detect_shell () const |
| Detect the user's shell from the SHELL environment variable. More... | |
| bool | write_file (const fs::path &path, std::string_view content) const |
| Write content to a file, creating parent directories if needed. More... | |
| std::vector< std::string > | expand_plugin_path (const std::string &path) const |
| Expand a plugin path (file or directory) into a list of .so files. More... | |
Private Attributes | |
| std::vector< std::string > | m_subcommands |
| List of registered subcommand names. More... | |
| std::map< const MaCh3ArgumentParser *, IModule * > | m_module_map |
| Map of parsers to core modules (non-owning) More... | |
| std::map< const MaCh3ArgumentParser *, std::unique_ptr< DynamicPlugin > > | m_dynamic_plugin_map |
| Map of parsers to dynamic plugins (owning) More... | |
Static Private Attributes | |
| static constexpr std::string_view | BASH_COMPLETION |
| static constexpr std::string_view | ZSH_COMPLETION |
Main program class that manages modules, plugins, and command-line parsing.
This class extends MaCh3ArgumentParser to provide functionality for:
Definition at line 26 of file MaCh3Program.hpp.
|
inlinevirtual |
Destructor that unloads all dynamic plugins.
Definition at line 31 of file MaCh3Program.hpp.
| void M3::MaCh3Program::add_core_module | ( | IModule & | module | ) |
Add a core module to the program.
| module | Reference to the module to be added |
Definition at line 104 of file MaCh3Program.cpp.
| void M3::MaCh3Program::completions | ( | const std::string & | prefix | ) | const |
Generate completion suggestions for the given prefix.
| prefix | The prefix string to match against available subcommands |
Definition at line 70 of file MaCh3Program.cpp.
|
private |
Detect the user's shell from the SHELL environment variable.
Definition at line 28 of file MaCh3Program.cpp.
|
private |
Expand a plugin path (file or directory) into a list of .so files.
Expand a plugin path to a list of shared library files.
| path | Path to a plugin file or directory containing plugins |
If the path is a file, returns it directly. If it's a directory, returns all .so files found in that directory.
| path | Path to a plugin file or directory |
Definition at line 189 of file MaCh3Program.cpp.
| void M3::MaCh3Program::install_completions | ( | ) | const |
Install shell completion scripts for bash and zsh.
Definition at line 39 of file MaCh3Program.cpp.
| void M3::MaCh3Program::load_dynamic_plugins | ( | ) |
Load dynamic plugins from the MACH3_PLUGINS environment variable.
Load dynamic plugins from paths specified in MACH3_PLUGINS environment variable.
Reads the MACH3_PLUGINS environment variable (colon-separated paths), loads each .so file, and registers the plugins with the program. Each plugin must export create_plugin and destroy_plugin functions.
Definition at line 116 of file MaCh3Program.cpp.
| int M3::MaCh3Program::Run | ( | ) |
Run the selected subcommand.
Execute the selected subcommand.
Determines which subcommand was invoked and runs the corresponding module or plugin.
Definition at line 164 of file MaCh3Program.cpp.
| void M3::MaCh3Program::unload_dynamic_plugins | ( | ) |
Unload all dynamically loaded plugins.
Unload all dynamic plugins and clean up resources.
Clears the plugin map. Smart pointers automatically handle cleanup.
Definition at line 155 of file MaCh3Program.cpp.
|
private |
Write content to a file, creating parent directories if needed.
| path | Filesystem path to write to |
| content | Content to write to the file |
Definition at line 16 of file MaCh3Program.cpp.
|
staticconstexprprivate |
Definition at line 78 of file MaCh3Program.hpp.
|
private |
Map of parsers to dynamic plugins (owning)
Definition at line 76 of file MaCh3Program.hpp.
|
private |
Map of parsers to core modules (non-owning)
Definition at line 75 of file MaCh3Program.hpp.
|
private |
List of registered subcommand names.
Definition at line 74 of file MaCh3Program.hpp.
|
staticconstexprprivate |
Definition at line 86 of file MaCh3Program.hpp.