switched commandfunction to vector<string>

This commit is contained in:
Nicholas O'Connor 2017-03-23 15:13:52 -07:00
parent ad670b5033
commit b4f5740006
8 changed files with 17 additions and 8 deletions

View File

@ -9,7 +9,7 @@
using namespace std; using namespace std;
namespace cellar { namespace cellar {
namespace commands { namespace commands {
typedef void (*CommandFunction)(int, char*[]); typedef void (*CommandFunction)(int, vector<string>);
extern map<string, CommandFunction> command_map; extern map<string, CommandFunction> command_map;
void add_command(string, CommandFunction); void add_command(string, CommandFunction);

View File

@ -11,7 +11,7 @@ namespace cellar {
with open("src/bottles/commands.txt") as commandsfile: with open("src/bottles/commands.txt") as commandsfile:
for line in commandsfile: for line in commandsfile:
item = line.strip().split(" ") item = line.strip().split(" ")
cog.outl("extern void {0} (int, char**);".format(item[1])) cog.outl("extern void {0} (int, vector<string>);".format(item[1]))
]]]*/ ]]]*/
//[[[end]]] //[[[end]]]
} }

View File

@ -1,10 +1,12 @@
#include <iostream> #include <iostream>
#include <string>
#include <vector>
#include "bottles.hpp" #include "bottles.hpp"
#include "internal/bottles.hpp" #include "internal/bottles.hpp"
using namespace std; using namespace std;
void cellar::bottles::switch_active_bottle(int argc, char** argv) { void cellar::bottles::switch_active_bottle(int argc, vector<string> argv) {
cout << argc << endl; cout << argc << endl;
} }

View File

@ -2,6 +2,7 @@
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <string> #include <string>
#include <vector>
#include "bottles.hpp" #include "bottles.hpp"
#include "internal/bottles.hpp" #include "internal/bottles.hpp"
@ -9,7 +10,7 @@
using namespace std; using namespace std;
using namespace cellar::bottles; using namespace cellar::bottles;
void cellar::bottles::print_active_bottle(int argc, char** argv) { void cellar::bottles::print_active_bottle(int argc, vector<string> argv) {
map<string, Bottle> bottlemap = get_bottles(); map<string, Bottle> bottlemap = get_bottles();
if (bottlemap.find(".wine") == bottlemap.end()) { // not found if (bottlemap.find(".wine") == bottlemap.end()) { // not found
cout << "no active wine bottle" << endl; cout << "no active wine bottle" << endl;

View File

@ -75,7 +75,7 @@ DLL_PUBLIC map<string, Bottle> cellar::bottles::get_bottles() {
return result; return result;
} }
void cellar::bottles::print_bottles(int argc, char** argv) { void cellar::bottles::print_bottles(int argc, vector<string> argv) {
map<string, Bottle> bottles = get_bottles(); map<string, Bottle> bottles = get_bottles();
for (auto item : bottles) { for (auto item : bottles) {

View File

@ -43,7 +43,9 @@ int main(int argc, char* argv[]) {
string usercmd = command.getValue(); string usercmd = command.getValue();
if (commands::command_map.count(usercmd) > 0) { if (commands::command_map.count(usercmd) > 0) {
commands::command_map[usercmd](argc, argv); int subargc = 0;
vector<string> subargv;
commands::command_map[usercmd](subargc, subargv);
} else { } else {
cerr << "invalid command: " << usercmd << endl; cerr << "invalid command: " << usercmd << endl;
return 1; return 1;

View File

@ -1,4 +1,6 @@
#include <iostream> #include <iostream>
#include <string>
#include <vector>
#include "commands.hpp" #include "commands.hpp"
#include "cellar.hpp" #include "cellar.hpp"
@ -16,7 +18,7 @@ vector<string> cellar::commands::list_commands() {
return result; return result;
} }
void help_command(int argc, char** argv) { void help_command(int argc, vector<string> argv) {
vector<string> commands = list_commands(); vector<string> commands = list_commands();
cellar::print_header(); cellar::print_header();

View File

@ -1,5 +1,7 @@
// vim: filetype=cpp : // vim: filetype=cpp :
#include <iostream> #include <iostream>
#include <string>
#include <vector>
#include "commands.hpp" #include "commands.hpp"
#include "version.hpp" #include "version.hpp"
@ -38,7 +40,7 @@ string cellar::version::short_version() {
//[[[end]]] //[[[end]]]
} }
void print_version(int argc, char** argv) { void print_version(int argc, vector<string> argv) {
cout << short_version() << endl; cout << short_version() << endl;
} }
cellar::commands::CommandFunction versioncmd = cellar::commands::command_map["version"] = &print_version; cellar::commands::CommandFunction versioncmd = cellar::commands::command_map["version"] = &print_version;