36 lines
737 B
C++
36 lines
737 B
C++
#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);
|
|
}
|
|
|
|
size_t Commands::howMany(){
|
|
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
|
|
|