description implementation! version already has one
This commit is contained in:
parent
a5a8fb284c
commit
de77c55df7
@ -77,8 +77,18 @@ endfunction(cellar_library)
|
||||
cellar_library(bottles)
|
||||
cellar_library(launch)
|
||||
|
||||
add_executable(cellar ${src}/cellar.cpp ${src}/commands.cpp ${src}/fs.cpp
|
||||
${src}/version.cpp ${src}/output.cpp ${src}/help/help.cpp)
|
||||
file(GLOB coresources RELATIVE "${CMAKE_SOURCE_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/src/*.cpp")
|
||||
file(GLOB corecoggedsources RELATIVE "${CMAKE_SOURCE_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/src/*.cpp.cog")
|
||||
foreach(corecog ${corecoggedsources})
|
||||
string(REGEX REPLACE ".cog\$" "" this "${corecog}")
|
||||
set(coresources ${coresources} ${this})
|
||||
endforeach(corecog)
|
||||
|
||||
get_sources("src/help/*.cpp" helpsources)
|
||||
|
||||
add_executable(cellar ${coresources} ${helpsources})
|
||||
target_link_libraries(cellar ${cellar_LIBRARIES} ${Boost_LIBRARIES})
|
||||
add_dependencies(cellar cog) # effectively redundant but a couple of the bin's
|
||||
# files are cogged, so this is mostly for people
|
||||
|
@ -9,6 +9,7 @@ using namespace std;
|
||||
namespace cellar {
|
||||
namespace help {
|
||||
extern void set_description(string,string);
|
||||
extern string get_description(string);
|
||||
}
|
||||
}
|
||||
|
||||
|
26
src/help/descriptions.cpp
Normal file
26
src/help/descriptions.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "help.hpp"
|
||||
|
||||
map<string,string> description_map;
|
||||
|
||||
void cellar::help::set_description(string command, string description) {
|
||||
if (description.empty()) {
|
||||
if (description_map.find(command) == description_map.end()) { // not found
|
||||
return; // no description no cry
|
||||
} else {
|
||||
description_map.erase(command);
|
||||
}
|
||||
} else { // setting description
|
||||
description_map[command] = description;
|
||||
}
|
||||
}
|
||||
|
||||
string cellar::help::get_description(string command) {
|
||||
if (description_map.find(command) == description_map.end()) { // not found
|
||||
return "";
|
||||
} else {
|
||||
return description_map.at(command);
|
||||
}
|
||||
}
|
@ -1,28 +1,32 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cellar.hpp"
|
||||
#include "internal/core.hpp"
|
||||
#include "help.cpp"
|
||||
#include "help.hpp"
|
||||
#include "output.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cellar;
|
||||
|
||||
void cellar::commands::help_command(int argc, vector<string> argv) {
|
||||
vector<string> commands = list_commands();
|
||||
cellar::print_header();
|
||||
|
||||
cout << "You have these commands:\n" << endl;
|
||||
cout << endl; // TODO: cellar::output function for code clarity
|
||||
|
||||
int num_columns = 4;
|
||||
int cur_column = 1;
|
||||
output::statement("You have these commands:");
|
||||
stringstream sstr;
|
||||
for (string command : commands) {
|
||||
cout << "\t" << command;
|
||||
if (cur_column == num_columns) {
|
||||
cout << endl;
|
||||
cur_column = 1;
|
||||
} else {
|
||||
cur_column++;
|
||||
sstr << "\t" << command;
|
||||
|
||||
string desc = help::get_description(command);
|
||||
if (!desc.empty()) {
|
||||
sstr << " - " << desc;
|
||||
}
|
||||
output::statement(sstr.str());
|
||||
sstr.str("");
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user