Changeset 7277
- Timestamp:
- Aug 31, 2010, 1:03:09 AM (14 years ago)
- Location:
- code/branches/consolecommands3/src/libraries/core/command
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc
r7236 r7277 45 45 SetConsoleCommand("unhide", &CommandExecutor::unhide) 46 46 .argumentCompleter(0, autocompletion::hiddencommand()); 47 48 SetConsoleCommand("alias", &CommandExecutor::alias) 49 .argumentCompleter(1, autocompletion::command()); 47 50 48 51 /* static */ CommandExecutor& CommandExecutor::getInstance() … … 157 160 return CommandExecutor::queryMT(command); 158 161 } 162 163 /* static */ void CommandExecutor::alias(const std::string& alias, const std::string& command) 164 { 165 CommandEvaluation evaluation = CommandExecutor::evaluate(command); 166 if (evaluation.isValid()) 167 { 168 ExecutorPtr executor = new Executor(*evaluation.getConsoleCommand()->getExecutor().get()); 169 170 if (!evaluation.evaluateParams()) 171 { 172 for (size_t i = 0; i < MAX_FUNCTOR_ARGUMENTS; ++i) 173 executor->setDefaultValue(i, evaluation.getEvaluatedParameter(i)); 174 } 175 176 SubString tokens(alias, " "); 177 178 if ((tokens.size() == 1 && ConsoleCommand::getCommand(tokens[0])) || (tokens.size() == 2 && ConsoleCommand::getCommand(tokens[0], tokens[1]))) 179 { 180 COUT(1) << "Error: A command with name \"" << alias << "\" already exists." << std::endl; 181 return; 182 } 183 184 if (tokens.size() == 1) 185 createConsoleCommand(tokens[0], executor); 186 else if (tokens.size() == 2) 187 createConsoleCommand(tokens[0], tokens[1], executor); 188 else 189 COUT(1) << "Error: \"" << alias << "\" is not a valid alias name (must have one or two words)." << std::endl; 190 } 191 else 192 COUT(1) << "Error: \"" << command << "\" is not a valid command (did you mean \"" << evaluation.getCommandSuggestion() << "\"?)." << std::endl; 193 } 159 194 } -
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h
r7234 r7277 60 60 61 61 static MultiType unhide(const std::string& command); 62 static void alias(const std::string& alias, const std::string& command); 62 63 static void _autocomplete(const std::string& group, const std::string& name) {} 63 64
Note: See TracChangeset
for help on using the changeset viewer.