cellar/src/cellar.cpp

62 lines
1.8 KiB
C++
Raw Normal View History

2017-03-12 17:13:07 -07:00
#include <iostream>
#include <map>
#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
#include "config.h"
#include "tclap/CmdLine.h"
#include "json.hpp"
2017-03-12 17:13:07 -07:00
2017-03-13 19:03:07 -07:00
#include "bottles.hpp"
#include "cellar.hpp"
#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;
using namespace cellar;
using json = nlohmann::json;
2017-03-12 17:13:07 -07:00
void cellar::print_header() {
cout << "cellar - bottle management tool for WINE connoisseurs" << std::endl;
2017-03-22 20:42:08 -07:00
cout << version::short_version() << std::endl;
}
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);
TCLAP::UnlabeledMultiArg<string> subargs("subargs", "Sub-arguments", false, "", "subarg");
cmdparse.add(subargs);
cmdparse.parse(argc, argv);
2017-03-23 12:06:29 -07:00
for (auto item : commands::bottles_commands()) {
commands::command_map[item.first] = item.second;
}
string usercmd = command.getValue();
if (commands::command_map.count(usercmd) > 0) {
vector<string> subargv = subargs.getValue();
commands::command_map[usercmd](subargv.size(), subargv);
} 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-12 15:43:11 -07:00
}