Skip to content

Commit

Permalink
Revert "Remove --verbose in labs CLI: -l / --loglevel from #4919 is e…
Browse files Browse the repository at this point in the history
…nough"

This reverts commit fada36f.
  • Loading branch information
kbenne committed Nov 10, 2023
1 parent 31333f8 commit 2a399fc
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,41 @@ int main(int argc, char* argv[]) {

app.get_formatter()->column_width(35);

auto* const verboseOpt = app.add_flag_function(
"--verbose",
[](auto count) {
if (count == 1) {
fmt::print("Setting Log Level to Debug ({})\n", LogLevel::Debug);
openstudio::Logger::instance().standardOutLogger().setLogLevel(LogLevel::Debug);
} else if (count == 2) {
fmt::print("Setting Log Level to Trace ({})\n", LogLevel::Trace);
openstudio::Logger::instance().standardOutLogger().setLogLevel(LogLevel::Trace);
}
},
"Print the full log to STDOUT - sets verbosity to Debug if given once and Trace if given twice.");

// specify string->value mappings
const std::map<std::string, LogLevel> logLevelMap{
{"Trace", LogLevel::Trace}, {"Debug", LogLevel::Debug}, {"Info", LogLevel::Info},
{"Warn", LogLevel::Warn}, {"Error", LogLevel::Error}, {"Fatal", LogLevel::Fatal},
};
static constexpr std::array<std::string_view, 6> logLevelStrs = {"Trace", "Debug", "Info", "Warn", "Error", "Fatal"};

app
.add_option_function<LogLevel>(
"-l,--loglevel",
[](const LogLevel& level) {
fmt::print("Setting Log Level to {} ({})\n", logLevelStrs[static_cast<size_t>(level) - static_cast<size_t>(LogLevel::Trace)], std::to_string(level));
openstudio::Logger::instance().standardOutLogger().setLogLevel(level);
},
"LogLevel settings: One of {Trace, Debug, Info, Warn, Error, Fatal} [Default: Warn]")
->option_text("LEVEL")
->transform(CLI::CheckedTransformer(logLevelMap, CLI::ignore_case));
auto* const logLevelOpt =
app
.add_option_function<LogLevel>(
"-l,--loglevel",
[](const LogLevel& level) {
fmt::print("Setting Log Level to {} ({})\n", logLevelStrs[static_cast<size_t>(level) - static_cast<size_t>(LogLevel::Trace)],
std::to_string(level));
openstudio::Logger::instance().standardOutLogger().setLogLevel(level);
},
"LogLevel settings: One of {Trace, Debug, Info, Warn, Error, Fatal} [Default: Warn] Excludes: --verbose")
->excludes(verboseOpt)
->option_text("LEVEL")
->transform(CLI::CheckedTransformer(logLevelMap, CLI::ignore_case));

verboseOpt->excludes(logLevelOpt);

std::vector<std::string> executeRubyCmds;
CLI::Option* execRubyOption = app
Expand Down

0 comments on commit 2a399fc

Please sign in to comment.