description implementation! version already has one
This commit is contained in:
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user