epr24pr5-ojanssen2/main.cpp

62 lines
1.3 KiB
C++

#pragma once
#include "ActiveCommand.h"
#include "std_lib_inc.h"
#include "parameter_reader.h"
#include "HelpCommand.h"
#include "AddCommand.h"
#include "AssignCommand.h"
#include "DelCommand.h"
#include "Error.h"
#include "ListCommand.h"
#include "UnassignCommand.h"
using commands::SubCommand;
using commands::HelpCommand;
using commands::AddCommand;
using commands::ListCommand;
using commands::DelCommand;
using commands::AssignCommand;
using commands::UnassignCommand;
using commands::ActiveCommand;
using err::Error;
const vector<SubCommand*> handlers = {
new HelpCommand(),
new AddCommand(),
new ListCommand(),
new DelCommand(),
new AssignCommand(),
new UnassignCommand(),
new ActiveCommand(),
};
int main(int argc, char** argv)
{
if (argc < 2)
{
cout << "There are not enough args!\n";
return 0;
}
stringstream parameter = make_string_stream(argc, argv);
string command;
parameter >> command;
try
{
for (SubCommand* sc : handlers)
{
if (sc->get_name() == command)
{
sc->run(argc, parameter);
return 0;
}
}
}
catch (Error& e)
{
cout << e.get_nr() << ": " << e.what() << "\n";
}
cout << "101: Befehl ist unbekannt.\n";
return 0;
}