epr24pr5-ojanssen2/main.cpp

68 lines
1.5 KiB
C++

#pragma once
#include "ActiveCommand.h"
#include "AddCommand.h"
#include "AssignCommand.h"
#include "DelCommand.h"
#include "Error.h"
#include "HelpCommand.h"
#include "ListCommand.h"
#include "ShowCommand.h"
#include "UnassignCommand.h"
#include "parameter_reader.h"
#include "std_lib_inc.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 commands::ShowCommand;
using err::Error;
const vector<SubCommand*> handlers = {
new HelpCommand(),
new AddCommand(),
new ListCommand(),
new DelCommand(),
new AssignCommand(),
new UnassignCommand(),
new ActiveCommand(),
new ShowCommand(),
};
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(parameter);
if (sc->should_display_result())
cout << "100: Alles erfolgreich\n";
return 0;
}
}
}
catch (Error& e)
{
cout << e.get_nr() << ": " << e.what() << "\n";
return 0;
}
cout << "101: Befehl ist unbekannt.\n";
return 0;
}