cellar/src/cellar.cpp

46 lines
1016 B
C++
Raw Normal View History

2017-03-12 22:33:42 -07:00
#include <cstdlib>
#include <fstream>
2017-03-12 17:13:07 -07:00
#include <iostream>
#include <string>
#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>
#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;
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[]) {
string homepath = getenv("HOME");
vector<string> homedir = cellar::fs::listdir(homepath);
2017-03-12 22:33:42 -07:00
for (string item : homedir) {
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());
cout << "has a json" << endl;
}
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
}