forked from University/epr24pr5-ojanssen2
53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
#include "std_lib_inc.h"
|
|
#include "parameter_reader.h"
|
|
#include "SubCommand.h"
|
|
#include "HelpCommand.h"
|
|
#include "AddCommand.h"
|
|
#include "User.h"
|
|
#include "Manager.h"
|
|
#include <exception>
|
|
|
|
#include "FileError.h"
|
|
|
|
using commands::SubCommand;
|
|
using commands::HelpCommand;
|
|
using commands::AddCommand;
|
|
using util::Manager;
|
|
using err::FileError;
|
|
using err::FormatError;
|
|
|
|
const vector<SubCommand*> handlers = { new HelpCommand(), new AddCommand() };
|
|
|
|
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 sc->get_value();
|
|
}
|
|
}
|
|
}
|
|
catch (FormatError& e) {
|
|
cout << e.why() << "\n";
|
|
}
|
|
catch (FileError& e)
|
|
{
|
|
cout << e.why() << "\n";
|
|
}
|
|
catch (exception& e) {
|
|
cout << e.what() << "\n";
|
|
}
|
|
return 101;
|
|
}
|
|
|
|
|