From d9dfe9d984a5871e15d6f1c7d9d1515925ed7159 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 13 Jun 2022 13:30:13 +0200 Subject: CLI: Catch and report non-CLI11 related errors ... and ensure that the default logging is set up before. --- src/buildtool/main/main.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 3f74b4e1..435e8219 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -161,6 +161,9 @@ auto ParseCommandLineArguments(int argc, char const* const* argv) app.parse(argc, argv); } catch (CLI::Error& e) { std::exit(app.exit(e)); + } catch (std::exception const& ex) { + Logger::Log(LogLevel::Error, "Command line parse error: {}", ex.what()); + std::exit(kExitFailure); } if (*cmd_describe) { @@ -188,9 +191,13 @@ auto ParseCommandLineArguments(int argc, char const* const* argv) return clargs; } +void SetupDefaultLogging() { + LogConfig::SetLogLimit(kDefaultLogLevel); + LogConfig::SetSinks({LogSinkCmdLine::CreateFactory()}); +} + void SetupLogging(CommonArguments const& clargs) { LogConfig::SetLogLimit(clargs.log_limit); - LogConfig::SetSinks({LogSinkCmdLine::CreateFactory()}); if (clargs.log_file) { LogConfig::AddSink(LogSinkFile::CreateFactory( *clargs.log_file, LogSinkFile::Mode::Overwrite)); @@ -1237,6 +1244,7 @@ void DumpArtifactsToBuild( } // namespace auto main(int argc, char* argv[]) -> int { + SetupDefaultLogging(); try { auto arguments = ParseCommandLineArguments(argc, argv); -- cgit v1.2.3