From 91e7ba79906cdad98c55d769c38bddc5e56aa4d1 Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Thu, 23 Mar 2017 13:17:07 -0700 Subject: [PATCH] cogged bottle command code, should be easier to add commands --- CMakeLists.txt | 4 ++-- include/internal/bottles.hpp | 12 ++++++++++++ src/bottles/active.cpp | 11 +++++++++++ src/bottles/bottles.cpp | 11 +++-------- src/bottles/commands.cpp.cog | 28 ++++++++++++++++++++++++++++ src/bottles/commands.txt | 2 ++ 6 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 include/internal/bottles.hpp create mode 100644 src/bottles/active.cpp create mode 100644 src/bottles/commands.cpp.cog create mode 100644 src/bottles/commands.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cc4414..bd2a699 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,11 +35,11 @@ foreach(cogfile ${cogfiles}) set(coggedfiles ${coggedfiles} "${thisfile}") endforeach(cogfile) -add_library(bottles SHARED ${src}/bottles/bottles.cpp) +add_library(bottles SHARED ${src}/bottles/bottles.cpp + ${src}/bottles/active.cpp ${src}/bottles/commands.cpp) add_custom_target(cog ALL DEPENDS ${coggedfiles}) add_executable(cellar ${src}/cellar.cpp ${src}/commands.cpp ${src}/fs.cpp ${src}/version.cpp) -add_dependencies(cellar cog) target_link_libraries(cellar ${Boost_LIBRARIES} bottles) diff --git a/include/internal/bottles.hpp b/include/internal/bottles.hpp new file mode 100644 index 0000000..c8050d5 --- /dev/null +++ b/include/internal/bottles.hpp @@ -0,0 +1,12 @@ +#ifndef __INTERNAL_BOTTLES_HPP +#define __INTERNAL_BOTTLES_HPP +#pragma once + +namespace cellar { + namespace bottles { + extern void print_bottles(int,char**); + extern void print_active_bottle(int,char**); + } +} + +#endif // __INTERNAL_BOTTLES_HPP diff --git a/src/bottles/active.cpp b/src/bottles/active.cpp new file mode 100644 index 0000000..546e369 --- /dev/null +++ b/src/bottles/active.cpp @@ -0,0 +1,11 @@ +#include + +#include "bottles.hpp" +#include "internal/bottles.hpp" +#include "dll.hpp" + +using namespace std; + +DLL_PUBLIC void cellar::bottles::print_active_bottle(int argc, char** argv) { + cout << "i just want to make sure cmake likes it first" << endl; +} diff --git a/src/bottles/bottles.cpp b/src/bottles/bottles.cpp index 2a4d6e2..b558d29 100644 --- a/src/bottles/bottles.cpp +++ b/src/bottles/bottles.cpp @@ -10,7 +10,7 @@ #include "json.hpp" #include "bottles.hpp" -#include "commands.hpp" +#include "internal/bottles.hpp" #include "dll.hpp" #include "fs.hpp" @@ -33,7 +33,7 @@ DLL_PUBLIC map cellar::bottles::get_bottles() { string homepath = getenv("HOME"); vector homedir = cellar::fs::listdir(homepath); for (string item : homedir) { - if (item.substr(0,6) == ".wine.") { + if (item.substr(0,5) == ".wine") { Bottle output; string fullitem = homepath + "/" + item; @@ -75,7 +75,7 @@ DLL_PUBLIC map cellar::bottles::get_bottles() { return result; } -void print_bottles(int argc, char** argv) { +void cellar::bottles::print_bottles(int argc, char** argv) { map bottles = get_bottles(); for (auto item : bottles) { @@ -97,8 +97,3 @@ void print_bottles(int argc, char** argv) { cout << endl; } } -DLL_PUBLIC map cellar::commands::bottles_commands() { - map result; - result.insert(pair("list", &print_bottles)); - return result; -} diff --git a/src/bottles/commands.cpp.cog b/src/bottles/commands.cpp.cog new file mode 100644 index 0000000..ab101cf --- /dev/null +++ b/src/bottles/commands.cpp.cog @@ -0,0 +1,28 @@ +// vim: filetype=cpp : +#include + +#include "bottles.hpp" +#include "internal/bottles.hpp" +#include "commands.hpp" +#include "dll.hpp" + +using namespace std; +using namespace cellar::bottles; +using namespace cellar::commands; + +DLL_PUBLIC map cellar::commands::bottles_commands() { + map result; + /*[[[cog + import cog + + with open("src/bottles/commands.txt") as commandfile: + for line in commandfile: + linesplit = line.split(" ") + name = linesplit[0] + func = linesplit[1] + + cog.outl("result.insert(pair(\"{0}\", &{1}));".format(name, func)) + ]]]*/ + //[[[end]]] + return result; +} diff --git a/src/bottles/commands.txt b/src/bottles/commands.txt new file mode 100644 index 0000000..b4d6ef3 --- /dev/null +++ b/src/bottles/commands.txt @@ -0,0 +1,2 @@ +list print_bottles +active print_active_bottle