improvements to the help command, including outputting detailed descriptions
This commit is contained in:
26
src/help/details.cpp
Normal file
26
src/help/details.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "help.hpp"
|
||||
|
||||
map<string,string> details_map;
|
||||
|
||||
void cellar::help::set_details(string command, string details) {
|
||||
if (details.empty()) {
|
||||
if (details_map.find(command) == details_map.end()) { // not found
|
||||
return; // no details no cry
|
||||
} else {
|
||||
details_map.erase(command);
|
||||
}
|
||||
} else { // setting details
|
||||
details_map[command] = details;
|
||||
}
|
||||
}
|
||||
|
||||
string cellar::help::get_details(string command) {
|
||||
if (details_map.find(command) == details_map.end()) { // not found
|
||||
return "";
|
||||
} else {
|
||||
return details_map.at(command);
|
||||
}
|
||||
}
|
@@ -3,6 +3,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "cellar.hpp"
|
||||
#include "internal/core.hpp"
|
||||
#include "help.hpp"
|
||||
@@ -17,16 +19,41 @@ void cellar::commands::help_command(int argc, vector<string> argv) {
|
||||
|
||||
cout << endl; // TODO: cellar::output function for code clarity
|
||||
|
||||
output::statement("You have these commands:");
|
||||
stringstream sstr;
|
||||
for (string command : commands) {
|
||||
sstr << "\t" << command;
|
||||
|
||||
string desc = help::get_description(command);
|
||||
if (!desc.empty()) {
|
||||
sstr << " - " << desc;
|
||||
if (argc == 1) {
|
||||
output::statement("You have these commands:");
|
||||
stringstream sstr;
|
||||
for (string command : commands) {
|
||||
sstr << "\t" << command;
|
||||
|
||||
string desc = help::get_description(command);
|
||||
if (!desc.empty()) {
|
||||
sstr << " - " << desc;
|
||||
}
|
||||
output::statement(sstr.str());
|
||||
sstr.str("");
|
||||
}
|
||||
} else {
|
||||
string command = argv[1];
|
||||
stringstream sstr;
|
||||
sstr << "cellar " << command << " - ";
|
||||
|
||||
string desc = help::get_description(command);
|
||||
if (desc.empty()) { sstr << "no description is available."; }
|
||||
else { sstr << desc; }
|
||||
output::statement(sstr.str());
|
||||
sstr.str("");
|
||||
|
||||
cout << endl;
|
||||
|
||||
string details = help::get_details(command);
|
||||
if (details.empty()) { output::statement("no details available."); }
|
||||
else {
|
||||
vector<string> detaillines;
|
||||
boost::split(detaillines, details, boost::is_any_of("\n"));
|
||||
|
||||
for (string line : detaillines) {
|
||||
if (!line.empty()) { output::statement(line); }
|
||||
else { cout << endl; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
src/help/version
Normal file
1
src/help/version
Normal file
@@ -0,0 +1 @@
|
||||
No, really, that's all it does.
|
Reference in New Issue
Block a user