Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7277


Ignore:
Timestamp:
Aug 31, 2010, 1:03:09 AM (14 years ago)
Author:
landauf
Message:

added new console command "alias" that can bind commands (including arguments) to a new name

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  
    4545    SetConsoleCommand("unhide", &CommandExecutor::unhide)
    4646        .argumentCompleter(0, autocompletion::hiddencommand());
     47
     48    SetConsoleCommand("alias", &CommandExecutor::alias)
     49        .argumentCompleter(1, autocompletion::command());
    4750
    4851    /* static */ CommandExecutor& CommandExecutor::getInstance()
     
    157160        return CommandExecutor::queryMT(command);
    158161    }
     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    }
    159194}
  • code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h

    r7234 r7277  
    6060
    6161            static MultiType unhide(const std::string& command);
     62            static void alias(const std::string& alias, const std::string& command);
    6263            static void _autocomplete(const std::string& group, const std::string& name) {}
    6364
Note: See TracChangeset for help on using the changeset viewer.