61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
#ifndef COMMAND_REGISTRY_HPP
|
|
#define COMMAND_REGISTRY_HPP
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <functional>
|
|
#include <map>
|
|
#include <set>
|
|
#include <memory>
|
|
#include <iostream>
|
|
|
|
namespace dropshell {
|
|
|
|
struct CommandContext {
|
|
std::string exename;
|
|
std::string command;
|
|
std::vector<std::string> args;
|
|
|
|
// Add more fields as needed (e.g., config pointer, output stream, etc.)
|
|
};
|
|
|
|
struct CommandInfo {
|
|
std::vector<std::string> names;
|
|
std::function<int(const CommandContext&)> handler;
|
|
std::function<void(const CommandContext&)> autocomplete; // optional
|
|
bool hidden = false;
|
|
bool requires_config = true;
|
|
bool requires_install = true;
|
|
int min_args = 0;
|
|
int max_args = -1; // -1 = unlimited
|
|
std::string help_usage; // install SERVER [SERVICE]
|
|
std::string help_description; // Install/reinstall/update service(s). Safe/non-destructive.
|
|
std::string full_help; // detailed help for the command
|
|
};
|
|
|
|
class CommandRegistry {
|
|
public:
|
|
static CommandRegistry& instance();
|
|
|
|
void register_command(const CommandInfo& info);
|
|
|
|
// Returns nullptr if not found
|
|
const CommandInfo* find_command(const std::string& name) const;
|
|
|
|
// List all commands (optionally including hidden)
|
|
std::vector<std::string> list_commands(bool include_hidden = false) const;
|
|
std::vector<std::string> list_primary_commands(bool include_hidden = false) const;
|
|
|
|
// For autocomplete
|
|
void autocomplete(const CommandContext& ctx) const;
|
|
|
|
private:
|
|
CommandRegistry() = default;
|
|
std::map<std::string, std::shared_ptr<CommandInfo>> command_map_;
|
|
std::vector<std::shared_ptr<CommandInfo>> all_commands_;
|
|
};
|
|
|
|
} // namespace dropshell
|
|
|
|
#endif // COMMAND_REGISTRY_HPP
|