From e30cddee84075216d0f8f3aaaba0e88421cec9f4 Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Sun, 12 Mar 2017 23:10:04 -0700 Subject: [PATCH] .gitignore, beginning of cellar.json support --- .gitignore | 10 ++++++++++ src/cellar.cpp | 30 +++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..099b1d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.in +*.o +*/.deps + +compile +config.* +configure +depcomp +install-sh +missing diff --git a/src/cellar.cpp b/src/cellar.cpp index 768108d..853959d 100644 --- a/src/cellar.cpp +++ b/src/cellar.cpp @@ -1,20 +1,44 @@ #include +#include #include #include +#include #include #include #include +#include "json.hpp" #include "fs.hpp" using namespace std; +using json = nlohmann::json; int main(int argc, char* argv[]) { - vector homedir = cellar::fs::listdir(getenv("HOME")); + string homepath = getenv("HOME"); + vector homedir = cellar::fs::listdir(homepath); for (string item : homedir) { - cout << item; - cout << " "; + 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; } + } } cout << endl; return 0;