forked from University/epr24pr5-ojanssen2
65 lines
1.4 KiB
C++
65 lines
1.4 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(parameter);
|
|
if (sc->should_display_result())
|
|
cout << "100: Alles erfolgreich\n";
|
|
return sc->get_value();
|
|
}
|
|
}
|
|
}
|
|
catch (Error& e)
|
|
{
|
|
cout << e.get_nr() << ": " << e.what() << "\n";
|
|
return e.get_nr();
|
|
}
|
|
cout << "101: Befehl ist unbekannt.\n";
|
|
return 101;
|
|
}
|