diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-07-02 00:33:19 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-07-02 00:33:19 +0100 |
| commit | 8c9688fff4446a1b0f5fe9a9be0c50084726cc4d (patch) | |
| tree | ca9a10be5795d976c0cbc73ad1111517bb4e22bf /nihil.cli/registry.ccm | |
| parent | 47999457e647352ae7e71d43c65e7b39ae5ca567 (diff) | |
| download | nihil-8c9688fff4446a1b0f5fe9a9be0c50084726cc4d.tar.gz nihil-8c9688fff4446a1b0f5fe9a9be0c50084726cc4d.tar.bz2 | |
CLI cleanups; fix the FreeBSD build
Diffstat (limited to 'nihil.cli/registry.ccm')
| -rw-r--r-- | nihil.cli/registry.ccm | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/nihil.cli/registry.ccm b/nihil.cli/registry.ccm index e5a7e29..5e31195 100644 --- a/nihil.cli/registry.ccm +++ b/nihil.cli/registry.ccm @@ -7,11 +7,28 @@ namespace nihil { export struct command; -// Register a command. This is guaranteed not to throw; errors will print -// a diagnostic and exit. -auto register_command(command *cmd) noexcept -> void; +/////////////////////////////////////////////////////////////////////// +// Command registry storage. This is where command::command() registers +// itself when the global command objects are constructed at startup. +// +// Because we sometimes create stub commands dynamically, the registry +// storage is a list of shared_ptr<command>. The "real" commands (which +// refer to global objects) will be created with a null deleter so they +// are never deleted. This allows real and stub commands to mix in the +// same command_tree. -// Get previously registered commands. -auto get_registered_commands() -> std::span<std::shared_ptr<command>>; +// Get the current registry. +auto get_registry() -> std::vector<std::shared_ptr<command>> & +{ + static auto commands = std::vector<std::shared_ptr<command>>(); + return commands; +} + +// Register a new command. +auto register_command(command *cmd) noexcept -> void +{ + auto constexpr null_deleter = [] (command const *) -> void {}; + get_registry().emplace_back(cmd, null_deleter); +} } // namespace nihil |
