the humble beginnings of a command system
This commit is contained in:
parent
9cf038ebc0
commit
4ef22255b0
@ -1,4 +1,4 @@
|
||||
bin_PROGRAMS = cellar
|
||||
cellar_CPPFLAGS = $(BOOST_CPPFLAGS)
|
||||
cellar_LDFLAGS = $(BOOST_LDFLAGS) $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB)
|
||||
cellar_SOURCES = cellar.cpp fs.cpp bottles.cpp
|
||||
cellar_SOURCES = cellar.cpp fs.cpp bottles.cpp commands.cpp
|
||||
|
@ -6,34 +6,17 @@
|
||||
#include "json.hpp"
|
||||
|
||||
#include "bottles.hpp"
|
||||
#include "commands.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cellar;
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
map<string, bottles::Bottle> bottles = bottles::get_bottles();
|
||||
for (auto& item : bottles) {
|
||||
cout << item.first << "- ";
|
||||
bottles::Bottle current = item.second;
|
||||
|
||||
switch (current.type) {
|
||||
case bottles::bottle_anonymous:
|
||||
cout << "anonymous wine bottle";
|
||||
break;
|
||||
case bottles::bottle_labelled:
|
||||
cout << current.config["name"];
|
||||
break;
|
||||
case bottles::bottle_symlink:
|
||||
cout << "symlink to ";
|
||||
cout << current.canonical_path;
|
||||
break;
|
||||
default:
|
||||
cout << "broken or unsupported wine bottle";
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
vector<string> commands = commands::list_commands();
|
||||
cout << "cellar - bottle management tool for WINE connoisseurs" << std::endl;
|
||||
for (string item : commands) {
|
||||
cout << item << " has loaded" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
19
src/commands.cpp
Normal file
19
src/commands.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "commands.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cellar::commands;
|
||||
|
||||
map<string, CommandFunction> cellar::commands::command_map;
|
||||
|
||||
bool cellar::commands::add_command(string name, CommandFunction func) {
|
||||
command_map[name] = func;
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<string> cellar::commands::list_commands() {
|
||||
vector<string> result;
|
||||
for (auto& item : command_map) {
|
||||
result.push_back(item.first);
|
||||
}
|
||||
return result;
|
||||
}
|
20
src/commands.hpp
Normal file
20
src/commands.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef __COMMANDS_HPP
|
||||
#define __COMMANDS_HPP
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
namespace cellar {
|
||||
namespace commands {
|
||||
typedef void (*CommandFunction)(int, char*[]);
|
||||
extern map<string, CommandFunction> command_map;
|
||||
|
||||
bool add_command(string, CommandFunction);
|
||||
vector<string> list_commands();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __COMMANDS_HPP
|
Loading…
Reference in New Issue
Block a user