From f4de6406bbd72f5778d4fb2bad727c26423866f7 Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Fri, 24 Mar 2017 20:01:25 -0700 Subject: [PATCH] verbose output is now a thing --- include/cellar.hpp | 2 ++ include/output.hpp | 8 ++++++-- src/cellar.cpp.cog | 31 +++++++++++++++++++++++++++++++ src/output.cpp | 19 ++++++++++++++++--- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/include/cellar.hpp b/include/cellar.hpp index 511c4b9..4704cd6 100644 --- a/include/cellar.hpp +++ b/include/cellar.hpp @@ -9,6 +9,8 @@ using namespace std; namespace cellar { extern void print_header(); extern void print_version(int,vector); + + extern bool verbose; } #endif // __CELLAR_HPP diff --git a/include/output.hpp b/include/output.hpp index 87d258d..22bf65b 100644 --- a/include/output.hpp +++ b/include/output.hpp @@ -5,10 +5,14 @@ namespace cellar { namespace output { - extern void statement(std::string parm); - extern void warning(std::string parm); + extern void statement(std::string); + extern void warning(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 void detect_colors(); } diff --git a/src/cellar.cpp.cog b/src/cellar.cpp.cog index 46967a3..0b9bd4b 100644 --- a/src/cellar.cpp.cog +++ b/src/cellar.cpp.cog @@ -28,6 +28,8 @@ using namespace std; using namespace cellar; using json = nlohmann::json; +bool cellar::verbose; + void cellar::print_header() { output::statement("cellar - bottle management tool for WINE connoisseurs"); 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 versionstr = version::short_version(); TCLAP::CmdLine cmdparse(desc, ' ', versionstr, false); + + TCLAP::SwitchArg verbosearg("v", "verbose", "Enables extra output"); + cmdparse.add(verbosearg); TCLAP::UnlabeledValueArg command("command", "Specific command to run.", true, "help", "command"); cmdparse.add(command); @@ -53,18 +58,44 @@ int main(int argc, char* argv[]) { cmdparse.parse(argc, argv); + verbose = verbosearg.getValue(); + // hardcoded because it's special + vector core_cmdnames; // mostly for verbose output for (auto item : commands::core_commands()) { 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 import cog with open("src/modules.txt") as modules: for module in modules: cog.out(""" + vector """ + module.strip() + """_cmdnames; for (auto item : commands::""" + module.strip() + """_commands()) { 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) ]]]*/ diff --git a/src/output.cpp b/src/output.cpp index 82d59e1..b84c20c 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -3,6 +3,7 @@ #include #include "ansicol.hpp" +#include "cellar.hpp" #include "output.hpp" 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) { cout << ansicol::green << " >"; cout << ansicol::green_bold << "> "; @@ -31,7 +34,11 @@ void cellar::output::statement(string str_message) { 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) { cerr << ansicol::yellow << " >"; cerr << ansicol::yellow_bold << "> "; @@ -42,7 +49,11 @@ void cellar::output::warning(string str_message) { 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) { cerr << ansicol::red << " >"; cerr << ansicol::red_bold << "> "; @@ -53,3 +64,5 @@ void cellar::output::error(string str_message) { cerr << str_message << endl; } +void cellar::output::error(string str_message) { statement(str_message, false); } +