2017-03-12 22:33:42 -07:00
|
|
|
#include <cstdlib>
|
2017-03-12 23:10:04 -07:00
|
|
|
#include <fstream>
|
2017-03-12 17:13:07 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
2017-03-12 23:10:04 -07:00
|
|
|
#include <sstream>
|
2017-03-12 22:33:42 -07:00
|
|
|
#include <vector>
|
2017-03-12 17:13:07 -07:00
|
|
|
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
#include <boost/filesystem/path.hpp>
|
2017-03-12 23:10:04 -07:00
|
|
|
#include "json.hpp"
|
2017-03-12 17:13:07 -07:00
|
|
|
|
2017-03-12 22:33:42 -07:00
|
|
|
#include "fs.hpp"
|
2017-03-12 17:13:07 -07:00
|
|
|
|
2017-03-12 22:33:42 -07:00
|
|
|
using namespace std;
|
2017-03-12 23:10:04 -07:00
|
|
|
using json = nlohmann::json;
|
2017-03-12 17:13:07 -07:00
|
|
|
|
2017-03-12 22:33:42 -07:00
|
|
|
int main(int argc, char* argv[]) {
|
2017-03-12 23:10:04 -07:00
|
|
|
string homepath = getenv("HOME");
|
|
|
|
vector<string> homedir = cellar::fs::listdir(homepath);
|
2017-03-12 22:33:42 -07:00
|
|
|
for (string item : homedir) {
|
2017-03-12 23:10:04 -07:00
|
|
|
if (item.substr(0,5) == ".wine") {
|
|
|
|
cout << item;
|
|
|
|
cout << " ";
|
|
|
|
|
|
|
|
string jsonpath = homepath + "/" + item + "/cellar.json";
|
|
|
|
if (boost::filesystem::exists(jsonpath)) {
|
|
|
|
try {
|
|
|
|
json config;
|
|
|
|
ifstream configstream(jsonpath);
|
|
|
|
stringstream sstr;
|
|
|
|
sstr << configstream.rdbuf();
|
|
|
|
config = json::parse(sstr.str());
|
2017-03-12 23:39:03 -07:00
|
|
|
|
|
|
|
cout << "- " << config["name"];
|
2017-03-12 23:10:04 -07:00
|
|
|
}
|
|
|
|
catch (const exception &exc) {
|
|
|
|
cout << "- bogus cellar.json file" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { cout << "- anonymous wine bottle" << endl; }
|
|
|
|
}
|
2017-03-12 22:33:42 -07:00
|
|
|
}
|
|
|
|
cout << endl;
|
2017-03-12 17:13:07 -07:00
|
|
|
return 0;
|
2017-03-12 15:43:11 -07:00
|
|
|
}
|