14class CommandController;
15class GlobalCommandController;
43 struct UnknownSubCommand {};
62 void tabCompletion(std::vector<std::string>& tokens)
const override;
69 void setToken(
void* token_) { assert(!token); token = token_; }
70 [[nodiscard]]
void*
getToken()
const {
return token; }
73 template<
typename... Args>
76 executeSubCommandImpl(subCmd, std::forward<Args>(args)...);
77 }
catch (UnknownSubCommand) {
78 unknownSubCommand(subCmd, std::forward<Args>(args)...);
87 template<
typename Func,
typename... Args>
88 void executeSubCommandImpl(std::string_view subCmd, std::string_view candidate, Func func, Args&&... args) {
89 if (subCmd == candidate) {
92 executeSubCommandImpl(subCmd, std::forward<Args>(args)...);
95 void executeSubCommandImpl(std::string_view ) {
96 throw UnknownSubCommand{};
99 template<
typename Func,
typename... Args>
100 void unknownSubCommand(std::string_view subCmd, std::string_view firstCandidate, Func , Args&&... args) {
101 unknownSubCommandImpl(
strCat(
"Unknown subcommand '", subCmd,
"'. Must be one of '", firstCandidate,
'\''),
102 std::forward<Args>(args)...);
104 template<
typename Func,
typename... Args>
105 void unknownSubCommandImpl(std::string message, std::string_view candidate, Func , Args&&... args) {
106 strAppend(message,
", '", candidate,
'\'');
107 unknownSubCommandImpl(message, std::forward<Args>(args)...);
110 template<
typename Func>
111 void unknownSubCommandImpl(std::string message, std::string_view lastCandidate, Func ) {
112 strAppend(message,
" or '", lastCandidate,
"'.");
113 throw CommandException(message);
117 bool allowInEmptyMachine =
true;
118 void* token =
nullptr;
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)
void executeSubCommand(std::string_view subCmd, Args &&... args)
bool isAllowedInEmptyMachine() const
virtual void execute(std::span< const TclObject > tokens, TclObject &result)=0
Execute this command.
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)