2016-03-11 14:49:24 +00:00
|
|
|
#include "commands.h"
|
|
|
|
|
|
|
|
using namespace Cmds;
|
|
|
|
|
|
|
|
Commands::Commands()
|
|
|
|
{
|
|
|
|
if(created) throw CommandsAlreadyCreatedException();
|
|
|
|
created=true;
|
|
|
|
|
|
|
|
//add builtin commands
|
|
|
|
add(new Command("cd", &cdExecute));
|
|
|
|
add(new Command("exit", &exitExecute));
|
|
|
|
add(new Command("help", &helpExecute));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Commands::add(Command* cmd){
|
|
|
|
commands.push_back(cmd);
|
|
|
|
}
|
|
|
|
|
2016-03-11 15:13:04 +00:00
|
|
|
size_t Commands::howMany(){
|
2016-03-11 14:49:24 +00:00
|
|
|
return commands.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Commands::launch(const vector<string>* args){
|
|
|
|
for(int i=0; i<commands.size(); i++){
|
|
|
|
if((commands[i]->getName())==args->operator [](0)){
|
|
|
|
return commands[i]->execute(args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw CommandNotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Commands::created = false;
|
|
|
|
|
|
|
|
//builtin commands
|
|
|
|
|