2017-03-12 17:13:07 -07:00
|
|
|
#include <iostream>
|
2017-03-22 19:02:14 -07:00
|
|
|
#include <map>
|
2017-03-22 23:23:15 -07:00
|
|
|
#include <sstream>
|
2017-03-12 17:13:07 -07:00
|
|
|
#include <string>
|
2017-03-12 22:33:42 -07:00
|
|
|
#include <vector>
|
2017-03-12 17:13:07 -07:00
|
|
|
|
2017-03-22 23:23:15 -07:00
|
|
|
#include "config.h"
|
|
|
|
#include "tclap/CmdLine.h"
|
2017-03-12 23:10:04 -07:00
|
|
|
#include "json.hpp"
|
2017-03-12 17:13:07 -07:00
|
|
|
|
2017-03-13 19:03:07 -07:00
|
|
|
#include "bottles.hpp"
|
2017-03-22 23:23:15 -07:00
|
|
|
#include "cellar.hpp"
|
2017-03-22 19:34:50 -07:00
|
|
|
#include "commands.hpp"
|
2017-03-22 20:42:08 -07:00
|
|
|
#include "version.hpp"
|
2017-03-12 17:13:07 -07:00
|
|
|
|
2017-03-12 22:33:42 -07:00
|
|
|
using namespace std;
|
2017-03-22 19:02:14 -07:00
|
|
|
using namespace cellar;
|
2017-03-12 23:10:04 -07:00
|
|
|
using json = nlohmann::json;
|
2017-03-12 17:13:07 -07:00
|
|
|
|
2017-03-22 23:23:15 -07:00
|
|
|
void cellar::print_header() {
|
2017-03-22 19:34:50 -07:00
|
|
|
cout << "cellar - bottle management tool for WINE connoisseurs" << std::endl;
|
2017-03-22 20:42:08 -07:00
|
|
|
cout << version::short_version() << std::endl;
|
2017-03-22 23:23:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
if (argc == 1) {
|
|
|
|
print_header();
|
|
|
|
cout << "\n(try \"cellar help\" if you're confused)" << endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const string desc = "bottle management tool for WINE connoisseurs";
|
|
|
|
const string versionstr = version::short_version();
|
|
|
|
TCLAP::CmdLine cmdparse(desc, ' ', versionstr, false);
|
|
|
|
TCLAP::UnlabeledValueArg<string> command("command", "Specific command to run.", true, "help", "command");
|
|
|
|
cmdparse.add(command);
|
|
|
|
|
|
|
|
cmdparse.parse(argc, argv);
|
|
|
|
|
|
|
|
string usercmd = command.getValue();
|
|
|
|
if (commands::command_map.count(usercmd) > 0) {
|
|
|
|
commands::command_map[usercmd](argc, argv);
|
|
|
|
} else {
|
|
|
|
cerr << "invalid command: " << usercmd << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} catch (TCLAP::ArgException &exc) {
|
|
|
|
cerr << "Invalid argument. (" << exc.argId() << ": " << exc.error() << ")" << endl;
|
|
|
|
return 1;
|
2017-03-22 19:34:50 -07:00
|
|
|
}
|
2017-03-12 15:43:11 -07:00
|
|
|
}
|