diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-06-13 13:30:13 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-06-13 13:30:13 +0200 |
commit | d9dfe9d984a5871e15d6f1c7d9d1515925ed7159 (patch) | |
tree | 94490453790c665386c75d201e699ff3131d7cc2 /src | |
parent | c08c4196a9393f549dd3c3db625af06f00291d27 (diff) | |
download | justbuild-d9dfe9d984a5871e15d6f1c7d9d1515925ed7159.tar.gz |
CLI: Catch and report non-CLI11 related errors
... and ensure that the default logging is set up before.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/main/main.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
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); |