13 class CommandController;
14 class GlobalCommandController;
42 struct UnknownSubCommand {};
61 void tabCompletion(std::vector<std::string>& tokens)
const override;
68 void setToken(
void* token_) { assert(!token); token = token_; }
69 [[nodiscard]]
void*
getToken()
const {
return token; }
72 template<
typename... Args>
75 executeSubCommandImpl(subcmd, std::forward<Args>(args)...);
76 }
catch (UnknownSubCommand) {
77 unknownSubCommand(subcmd, std::forward<Args>(args)...);
86 template<
typename Func,
typename... Args>
87 void executeSubCommandImpl(std::string_view subcmd, std::string_view candidate, Func func, Args&&... args) {
88 if (subcmd == candidate) {
91 executeSubCommandImpl(subcmd, std::forward<Args>(args)...);
94 void executeSubCommandImpl(std::string_view ) {
95 throw UnknownSubCommand{};
98 template<
typename Func,
typename... Args>
99 void unknownSubCommand(std::string_view subcmd, std::string_view firstCandidate, Func , Args&&... args) {
100 unknownSubCommandImpl(
strCat(
"Unknown subcommand '", subcmd,
"'. Must be one of '", firstCandidate,
'\''),
101 std::forward<Args>(args)...);
103 template<
typename Func,
typename... Args>
104 void unknownSubCommandImpl(std::string message, std::string_view candidate, Func , Args&&... args) {
105 strAppend(message,
", '", candidate,
'\'');
106 unknownSubCommandImpl(message, std::forward<Args>(args)...);
109 template<
typename Func>
110 void unknownSubCommandImpl(std::string message, std::string_view lastCandidate, Func ) {
111 strAppend(message,
" or '", lastCandidate,
"'.");
112 throw CommandException(message);
116 bool allowInEmptyMachine;
CliComm & getCliComm() const
CommandCompleter(const CommandCompleter &)=delete
CommandController & getCommandController() const
CommandCompleter & operator=(const CommandCompleter &)=delete
Interpreter & getInterpreter() const final
GlobalCommandController & getGlobalCommandController() const
void setToken(void *token_)
void setAllowedInEmptyMachine(bool value)
virtual void execute(span< const TclObject > tokens, TclObject &result)=0
Execute this command.
void executeSubCommand(std::string_view subcmd, Args &&... args)
bool isAllowedInEmptyMachine() const
virtual void tabCompletion(std::vector< std::string > &tokens) const =0
Attempt tab completion for this command.
This file implemented 3 utility functions:
std::string strCat(Ts &&...ts)
void strAppend(std::string &result, Ts &&...ts)