switched commandfunction to vector<string>
This commit is contained in:
parent
ad670b5033
commit
b4f5740006
@ -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);
|
||||||
|
@ -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]]]
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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) {
|
||||||
|
@ -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;
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user