converted executable-based commands to the new command API (as "core")
This commit is contained in:
parent
5a7353abc1
commit
325413f3f2
@ -1,9 +1,14 @@
|
||||
#ifndef __CELLAR_HPP
|
||||
#define __CELLAR_HPP
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cellar {
|
||||
void print_header();
|
||||
extern void print_header();
|
||||
extern void print_version(int,vector<string>);
|
||||
}
|
||||
|
||||
#endif // __CELLAR_HPP
|
||||
|
@ -14,6 +14,8 @@ namespace cellar {
|
||||
|
||||
void add_command(string, CommandFunction);
|
||||
vector<string> list_commands();
|
||||
|
||||
extern map<string,CommandFunction> core_commands();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// vim: filetype=cpp
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
@ -42,9 +43,18 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
cmdparse.parse(argc, argv);
|
||||
|
||||
for (auto item : commands::bottles_commands()) {
|
||||
commands::command_map[item.first] = item.second;
|
||||
}
|
||||
/*[[[cog
|
||||
import cog
|
||||
|
||||
with open("src/modules.txt") as modules:
|
||||
for module in modules:
|
||||
cog.out("""
|
||||
for (auto item : commands::""" + module.strip() + """_commands()) {
|
||||
commands::command_map[item.first] = item.second;
|
||||
}
|
||||
""", dedent=True, trimblanklines=True)
|
||||
]]]*/
|
||||
//[[[end]]]
|
||||
|
||||
string usercmd = command.getValue();
|
||||
if (commands::command_map.count(usercmd) > 0) {
|
@ -1,3 +1,4 @@
|
||||
// vim: filetype=cpp :
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -37,4 +38,20 @@ void help_command(int argc, vector<string> argv) {
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
CommandFunction helpcmd = command_map["help"] = &help_command;
|
||||
|
||||
map<string, CommandFunction> cellar::commands::core_commands() {
|
||||
map<string, CommandFunction> result;
|
||||
/*[[[cog
|
||||
import cog
|
||||
|
||||
with open("src/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;
|
||||
}
|
2
src/commands.txt
Normal file
2
src/commands.txt
Normal file
@ -0,0 +1,2 @@
|
||||
version print_version
|
||||
help help_command
|
2
src/modules.txt
Normal file
2
src/modules.txt
Normal file
@ -0,0 +1,2 @@
|
||||
core
|
||||
bottles
|
@ -3,6 +3,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cellar.hpp"
|
||||
#include "commands.hpp"
|
||||
#include "output.hpp"
|
||||
#include "version.hpp"
|
||||
@ -41,7 +42,6 @@ string cellar::version::short_version() {
|
||||
//[[[end]]]
|
||||
}
|
||||
|
||||
void print_version(int argc, vector<string> argv) {
|
||||
void cellar::print_version(int argc, vector<string> argv) {
|
||||
cellar::output::statement(short_version());
|
||||
}
|
||||
cellar::commands::CommandFunction versioncmd = cellar::commands::command_map["version"] = &print_version;
|
||||
|
Loading…
Reference in New Issue
Block a user