From 44a831a4b000579ac40a1241f2039001e0e739d4 Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Thu, 23 Mar 2017 00:02:38 -0700 Subject: [PATCH] list command --- cogrc | 2 +- src/Makefile.am | 2 +- src/bottles.cpp | 27 ++++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cogrc b/cogrc index 252f51d..3f3aeda 100644 --- a/cogrc +++ b/cogrc @@ -1,3 +1,3 @@ [version] release=no -release_version=0.3 +release_version=00 diff --git a/src/Makefile.am b/src/Makefile.am index 71a330d..9bf5dc7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ bin_PROGRAMS = cellar cellar_CPPFLAGS = $(BOOST_CPPFLAGS) cellar_LDFLAGS = $(BOOST_LDFLAGS) $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) -cellar_SOURCES = cellar.cpp fs.cpp bottles.cpp commands.cpp +cellar_SOURCES = commands.cpp cellar.cpp fs.cpp bottles.cpp # Generated files nodist_cellar_SOURCES = version.cpp diff --git a/src/bottles.cpp b/src/bottles.cpp index 7d714e0..032bd2d 100644 --- a/src/bottles.cpp +++ b/src/bottles.cpp @@ -10,6 +10,7 @@ #include "json.hpp" #include "bottles.hpp" +#include "commands.hpp" #include "fs.hpp" using namespace std; @@ -30,7 +31,7 @@ map cellar::bottles::get_bottles() { string homepath = getenv("HOME"); vector homedir = cellar::fs::listdir(homepath); for (string item : homedir) { - if (item.substr(0,5) == ".wine") { + if (item.substr(0,6) == ".wine.") { Bottle output; string fullitem = homepath + "/" + item; @@ -71,3 +72,27 @@ map cellar::bottles::get_bottles() { return result; } + +void print_bottles(int argc, char** argv) { + map bottles = get_bottles(); + + for (auto item : bottles) { + Bottle bottle = item.second; + cout << item.first << " - "; + switch (bottle.type) { + case bottle_anonymous: + cout << "anonymous wine bottle"; + break; + case bottle_symlink: + cout << "symlink to " << bottle.canonical_path; + break; + case bottle_labelled: + cout << bottle.config["name"]; + break; + default: + cout << "broken or unsupported wine bottle"; + } + cout << endl; + } +} +cellar::commands::CommandFunction listcmd = cellar::commands::command_map["list"] = &print_bottles;