verbose output is now a thing
This commit is contained in:
parent
4e67bd40c5
commit
f4de6406bb
@ -9,6 +9,8 @@ using namespace std;
|
||||
namespace cellar {
|
||||
extern void print_header();
|
||||
extern void print_version(int,vector<string>);
|
||||
|
||||
extern bool verbose;
|
||||
}
|
||||
|
||||
#endif // __CELLAR_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();
|
||||
}
|
||||
|
@ -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());
|
||||
@ -45,6 +47,9 @@ int main(int argc, char* argv[]) {
|
||||
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<string> 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<string> 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<string> """ + 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)
|
||||
]]]*/
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#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); }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user