verbose output is now a thing

This commit is contained in:
Nicholas O'Connor 2017-03-24 20:01:25 -07:00
parent 4e67bd40c5
commit f4de6406bb
4 changed files with 55 additions and 5 deletions

View File

@ -9,6 +9,8 @@ using namespace std;
namespace cellar { namespace cellar {
extern void print_header(); extern void print_header();
extern void print_version(int,vector<string>); extern void print_version(int,vector<string>);
extern bool verbose;
} }
#endif // __CELLAR_HPP #endif // __CELLAR_HPP

View File

@ -5,10 +5,14 @@
namespace cellar { namespace cellar {
namespace output { namespace output {
extern void statement(std::string parm); extern void statement(std::string);
extern void warning(std::string parm); extern void warning(std::string);
extern void error(std::string); extern void error(std::string);
extern void statement(std::string parm, bool);
extern void warning(std::string, bool);
extern void error(std::string, bool);
extern bool colors; extern bool colors;
extern void detect_colors(); extern void detect_colors();
} }

View File

@ -28,6 +28,8 @@ using namespace std;
using namespace cellar; using namespace cellar;
using json = nlohmann::json; using json = nlohmann::json;
bool cellar::verbose;
void cellar::print_header() { void cellar::print_header() {
output::statement("cellar - bottle management tool for WINE connoisseurs"); output::statement("cellar - bottle management tool for WINE connoisseurs");
output::statement(version::short_version()); output::statement(version::short_version());
@ -44,6 +46,9 @@ int main(int argc, char* argv[]) {
const string desc = "bottle management tool for WINE connoisseurs"; const string desc = "bottle management tool for WINE connoisseurs";
const string versionstr = version::short_version(); const string versionstr = version::short_version();
TCLAP::CmdLine cmdparse(desc, ' ', versionstr, false); TCLAP::CmdLine cmdparse(desc, ' ', versionstr, false);
TCLAP::SwitchArg verbosearg("v", "verbose", "Enables extra output");
cmdparse.add(verbosearg);
TCLAP::UnlabeledValueArg<string> command("command", "Specific command to run.", true, "help", "command"); TCLAP::UnlabeledValueArg<string> command("command", "Specific command to run.", true, "help", "command");
cmdparse.add(command); cmdparse.add(command);
@ -53,18 +58,44 @@ int main(int argc, char* argv[]) {
cmdparse.parse(argc, argv); cmdparse.parse(argc, argv);
verbose = verbosearg.getValue();
// hardcoded because it's special // hardcoded because it's special
vector<string> core_cmdnames; // mostly for verbose output
for (auto item : commands::core_commands()) { for (auto item : commands::core_commands()) {
commands::command_map[item.first] = item.second; commands::command_map[item.first] = item.second;
core_cmdnames.push_back(item.first);
} }
if (verbose) { // handling it here for efficiency
stringstream commandstring;
commandstring << "loading from core: ";
for (string item : core_cmdnames) {
commandstring << item << " ";
}
output::statement(commandstring.str(), true);
}
// as above, but cogged from src/modules.txt
// BULLSHIT: trying to use str.format on this string causes bizarre compiler errors
/*[[[cog /*[[[cog
import cog import cog
with open("src/modules.txt") as modules: with open("src/modules.txt") as modules:
for module in modules: for module in modules:
cog.out(""" cog.out("""
vector<string> """ + module.strip() + """_cmdnames;
for (auto item : commands::""" + module.strip() + """_commands()) { for (auto item : commands::""" + module.strip() + """_commands()) {
commands::command_map[item.first] = item.second; commands::command_map[item.first] = item.second;
""" + module.strip() + """_cmdnames.push_back(item.first);
}
if (verbose) {
stringstream commandstring;
commandstring << "loading from """ + module.strip() + """: ";
for (string item : """ + module.strip() + """_cmdnames) {
commandstring << item << " ";
}
output::statement(commandstring.str(), true);
} }
""", dedent=True, trimblanklines=True) """, dedent=True, trimblanklines=True)
]]]*/ ]]]*/

View File

@ -3,6 +3,7 @@
#include <unistd.h> #include <unistd.h>
#include "ansicol.hpp" #include "ansicol.hpp"
#include "cellar.hpp"
#include "output.hpp" #include "output.hpp"
using namespace std; using namespace std;
@ -20,7 +21,9 @@ void cellar::output::detect_colors() {
} }
} }
void cellar::output::statement(string str_message) { void cellar::output::statement(string str_message, bool verbose) {
if (verbose and !cellar::verbose) { return; }
if (colors) { if (colors) {
cout << ansicol::green << " >"; cout << ansicol::green << " >";
cout << ansicol::green_bold << "> "; cout << ansicol::green_bold << "> ";
@ -31,7 +34,11 @@ void cellar::output::statement(string str_message) {
cout << str_message << endl; cout << str_message << endl;
} }
void cellar::output::warning(string str_message) { void cellar::output::statement(string str_message) { statement(str_message, false); }
void cellar::output::warning(string str_message, bool verbose) {
if (verbose and !cellar::verbose) { return; }
if (colors) { if (colors) {
cerr << ansicol::yellow << " >"; cerr << ansicol::yellow << " >";
cerr << ansicol::yellow_bold << "> "; cerr << ansicol::yellow_bold << "> ";
@ -42,7 +49,11 @@ void cellar::output::warning(string str_message) {
cerr << str_message << endl; cerr << str_message << endl;
} }
void cellar::output::error(string str_message) { void cellar::output::warning(string str_message) { statement(str_message, false); }
void cellar::output::error(string str_message, bool verbose) {
if (verbose and !cellar::verbose) { return; }
if (colors) { if (colors) {
cerr << ansicol::red << " >"; cerr << ansicol::red << " >";
cerr << ansicol::red_bold << "> "; cerr << ansicol::red_bold << "> ";
@ -53,3 +64,5 @@ void cellar::output::error(string str_message) {
cerr << str_message << endl; cerr << str_message << endl;
} }
void cellar::output::error(string str_message) { statement(str_message, false); }