launching commands!

This commit is contained in:
Nicholas O'Connor 2017-03-23 21:20:26 -07:00
parent 325413f3f2
commit 1c91618f5c
13 changed files with 1781 additions and 4 deletions

View File

@ -54,11 +54,14 @@ add_library(bottles SHARED ${src}/bottles/bottles.cpp
${src}/bottles/activate.cpp) ${src}/bottles/activate.cpp)
add_dependencies(bottles cog) add_dependencies(bottles cog)
add_library(launch SHARED ${src}/launch/launch.cpp ${src}/launch/commands.cpp
${src}/launch/shortcuts.cpp)
add_custom_target(cog ALL DEPENDS ${coggedfiles}) add_custom_target(cog ALL DEPENDS ${coggedfiles})
add_executable(cellar ${src}/cellar.cpp ${src}/commands.cpp ${src}/fs.cpp add_executable(cellar ${src}/cellar.cpp ${src}/commands.cpp ${src}/fs.cpp
${src}/version.cpp ${src}/output.cpp) ${src}/version.cpp ${src}/output.cpp)
target_link_libraries(cellar ${Boost_LIBRARIES} bottles) target_link_libraries(cellar ${Boost_LIBRARIES} bottles launch)
install(TARGETS cellar bottles install(TARGETS cellar bottles
RUNTIME DESTINATION bin RUNTIME DESTINATION bin

View File

@ -30,9 +30,6 @@ namespace cellar {
}; };
extern map<string, Bottle> get_bottles(); extern map<string, Bottle> get_bottles();
} }
namespace commands {
extern map<string, cellar::commands::CommandFunction> bottles_commands();
}
} }
#endif // __BOTTLES_HPP #endif // __BOTTLES_HPP

View File

@ -3,6 +3,13 @@
#define __INTERNAL_BOTTLES_HPP #define __INTERNAL_BOTTLES_HPP
#pragma once #pragma once
#include <map>
#include <string>
#include "commands.hpp"
using namespace cellar::commands;
namespace cellar { namespace cellar {
namespace bottles { namespace bottles {
/*[[[cog /*[[[cog
@ -15,6 +22,9 @@ namespace cellar {
]]]*/ ]]]*/
//[[[end]]] //[[[end]]]
} }
namespace commands {
extern map<string, cellar::commands::CommandFunction> bottles_commands();
}
} }
#endif // __INTERNAL_BOTTLES_HPP #endif // __INTERNAL_BOTTLES_HPP

View File

@ -0,0 +1 @@
// dummy file

View File

@ -0,0 +1,30 @@
// vim: filetype=cpp :
#ifndef __INTERNAL_LAUNCH_HPP
#define __INTERNAL_LAUNCH_HPP
#pragma once
#include <map>
#include <string>
#include "commands.hpp"
using namespace cellar::commands;
namespace cellar {
namespace launch {
/*[[[cog
import cog
with open("src/launch/commands.txt") as commandsfile:
for line in commandsfile:
item = line.strip().split(" ")
cog.outl("extern void {0} (int, vector<string>);".format(item[1]))
]]]*/
//[[[end]]]
}
namespace commands {
extern map<string,CommandFunction> launch_commands();
}
}
#endif // __INTERNAL_LAUNCH_HPP

16
include/launch.hpp Normal file
View File

@ -0,0 +1,16 @@
#ifndef __LAUNCH_HPP
#define __LAUNCH_HPP
#pragma once
#include <string>
#include <vector>
using namespace std;
namespace cellar {
namespace launch {
extern void launch_program (vector<string>);
}
}
#endif // __LAUNCH_HPP

1622
include/subprocess.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,15 @@
#include "output.hpp" #include "output.hpp"
#include "version.hpp" #include "version.hpp"
/*[[[cog
import cog
with open("src/modules.txt") as modules:
for module in modules:
cog.outl("#include \"internal/{0}.hpp\"".format(module.strip()))
]]]*/
//[[[end]]]
using namespace std; using namespace std;
using namespace cellar; using namespace cellar;
using json = nlohmann::json; using json = nlohmann::json;

View File

@ -0,0 +1,28 @@
// vim: filetype=cpp :
#include <map>
#include "launch.hpp"
#include "internal/launch.hpp"
#include "commands.hpp"
#include "dll.hpp"
using namespace std;
using namespace cellar::launch;
using namespace cellar::commands;
DLL_PUBLIC map<string, CommandFunction> cellar::commands::launch_commands() {
map<string, CommandFunction> result;
/*[[[cog
import cog
with open("src/launch/commands.txt") as commandfile:
for line in commandfile:
linesplit = line.strip().split(" ")
name = linesplit[0]
func = linesplit[1]
cog.outl("result.insert(pair<string,CommandFunction>(\"{0}\", &{1}));".format(name, func))
]]]*/
//[[[end]]]
return result;
}

3
src/launch/commands.txt Normal file
View File

@ -0,0 +1,3 @@
launch launch_command
winecfg launch_winecfg
regedit launch_regedit

30
src/launch/launch.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <string>
#include <vector>
#include <unistd.h>
#include <boost/algorithm/string/join.hpp>
#include "subprocess.hpp"
#include "launch.hpp"
#include "internal/launch.hpp"
#include "output.hpp"
using namespace std;
using namespace cellar;
void cellar::launch::launch_program(vector<string> args) {
vector<string> wineargs = args;
wineargs[0] = "wine";
string winelaunch = boost::algorithm::join(wineargs, " ");
auto wine = subprocess::Popen(winelaunch);
wine.wait();
}
void cellar::launch::launch_command(int argc, vector<string> args) {
if (argc == 1) {
output::error("forgot to specify a command");
return;
}
launch::launch_program(args);
}

27
src/launch/shortcuts.cpp Normal file
View File

@ -0,0 +1,27 @@
#include <string>
#include <vector>
#include "launch.hpp"
#include "internal/launch.hpp"
using namespace std;
void cellar::launch::launch_winecfg(int argc, vector<string> argv) {
// cheap alias for "cellar launch winecfg"
vector<string> launchargs;
launchargs.push_back("cellar launch");
launchargs.push_back("winecfg");
cellar::launch::launch_program(launchargs);
}
void cellar::launch::launch_regedit(int argc, vector<string> argv) {
// cheap alias for "cellar launch regedit"
vector<string> launchargs;
launchargs.push_back("cellar launch");
launchargs.push_back("regedit");
if (argc > 1) { launchargs.push_back(argv[1]); }
cellar::launch::launch_program(launchargs);
}

View File

@ -1,2 +1,3 @@
core core
bottles bottles
launch