VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::CommandBuilder Class Reference

Fluent command registration, returned by CommandManager::Add. More...

#include <CommandBuilder.hpp>

Public Types

using Installer = std::function< void(CommandDefinition)>
 

Public Member Functions

 CommandBuilder (Installer install, std::string_view name)
 
CommandBuilder & Alias (std::string_view alias)
 
CommandBuilder & Describe (std::string_view text)
 
CommandBuilder & Permission (std::string_view permission)
 
CommandBuilder & Anywhere ()
 
CommandBuilder & ServerOnly ()
 
CommandBuilder & UsageKey (std::string_view key)
 
template<class F >
void Run (F &&handler)
 

Detailed Description

Fluent command registration, returned by CommandManager::Add.

commands.Add("ban")
.Describe("Ban a player.")
.Alias("b")
.Permission("admin.ban")
std::string name = t->Name(); // capture first: a ban drops the target
std::string reason = why.ValueOr(c.Translations.Get("reason.bannedByAdmin"));
if (!app.Ban(*c.Player, *t.Value, reason, d.Value))
return c.Fail("cmd.banFailed");
return c.Ok("cmd.banSuccess", {{"name", name}});
});
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
Who invoked the command, and how to answer them.

Run installs the command. The manager owns it for the plugin load cycle.

Definition at line 191 of file CommandBuilder.hpp.

Member Typedef Documentation

◆ Installer

How Run hands the finished definition back to the manager that made this builder.

Definition at line 195 of file CommandBuilder.hpp.

Constructor & Destructor Documentation

◆ CommandBuilder()

VoltMod::CommandBuilder::CommandBuilder ( Installer  install,
std::string_view  name 
)
inline

Definition at line 197 of file CommandBuilder.hpp.

References VoltMod::CommandDefinition::Name.

Member Function Documentation

◆ Alias()

CommandBuilder & VoltMod::CommandBuilder::Alias ( std::string_view  alias)
inline

Another name for the same command. Collisions are refused and logged at registration.

Definition at line 203 of file CommandBuilder.hpp.

References VoltMod::CommandDefinition::Aliases, and VoltMod::ReadFile().

◆ Anywhere()

CommandBuilder & VoltMod::CommandBuilder::Anywhere ( )
inline

Also register a tier1 ConCommand, so players can type it in their console and the server can run it from its console, rcon, cfg files and ExecuteServerCommand.

Definition at line 225 of file CommandBuilder.hpp.

References VoltMod::CommandDefinition::Access, and VoltMod::Anywhere.

◆ Describe()

CommandBuilder & VoltMod::CommandBuilder::Describe ( std::string_view  text)
inline

Operator-facing description; also the console command's help text.

Definition at line 210 of file CommandBuilder.hpp.

References VoltMod::CommandDefinition::Description, and VoltMod::ReadFile().

◆ Permission()

CommandBuilder & VoltMod::CommandBuilder::Permission ( std::string_view  permission)
inline

Gate on Policy::Authorize, which denies while no plugin publishes IPermissions.

Definition at line 217 of file CommandBuilder.hpp.

References VoltMod::CommandDefinition::PermissionName, and VoltMod::ReadFile().

◆ Run()

template<class F >
void VoltMod::CommandBuilder::Run ( F &&  handler)
inline

Install the command. The handler takes a Caller and one Args:: value per argument; that list defines arity, parsing, and usage. A handler that returns nothing succeeds silently.

The command is unregistered when CommandManager is destroyed.

Definition at line 253 of file CommandBuilder.hpp.

References VoltMod::ReadFile().

◆ ServerOnly()

CommandBuilder & VoltMod::CommandBuilder::ServerOnly ( )
inline

Register only the ConCommand, for an operator command players cannot run.

Definition at line 232 of file CommandBuilder.hpp.

References VoltMod::CommandDefinition::Access, and VoltMod::ServerOnly.

◆ UsageKey()

CommandBuilder & VoltMod::CommandBuilder::UsageKey ( std::string_view  key)
inline

Translation key for the whole usage line, replacing the one derived from the argument types.

Definition at line 240 of file CommandBuilder.hpp.

References VoltMod::ReadFile(), and VoltMod::CommandDefinition::UsageKey.


The documentation for this class was generated from the following file: