Skip to content

Commit 4126e07

Browse files
authored
Move the implementation of Tool::main to the cc file to avoid include Error.hh in Tool.hh. This helps manage the includes of project couchbase-mobile-tools, (CBL-7589). (#2376)
1 parent 08e6b4a commit 4126e07

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

tool_support/Tool.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
//
1818

1919
#include "Tool.hh"
20+
#include "Error.hh"
2021
#include "Logging.hh"
2122
#include "linenoise.h"
2223
#include "utf8.h"
@@ -51,6 +52,26 @@ static constexpr const char* kHistoryFilePath = "~/.cblite_history";
5152

5253
Tool* Tool::instance;
5354

55+
int Tool::main(int argc, const char* argv[]) {
56+
try {
57+
if ( getenv("CLICOLOR") ) enableColor();
58+
_toolPath = std::string(argv[0]);
59+
std::vector<std::string> args;
60+
for ( int i = 1; i < argc; ++i ) args.push_back(argv[i]);
61+
_argTokenizer.reset(args);
62+
return run();
63+
} catch ( const exit_error& x ) { return x.status; } catch ( const fail_error& ) {
64+
return 1;
65+
} catch ( const litecore::error& x ) {
66+
errorOccurred(litecore::stringprintf("Uncaught LiteCore exception: %s", x.what()));
67+
if ( x.backtrace ) x.backtrace->writeTo(std::cerr);
68+
std::cerr << std::endl;
69+
} catch ( const std::exception& x ) {
70+
errorOccurred(litecore::stringprintf("Uncaught C++ exception: %s", x.what()));
71+
} catch ( ... ) { errorOccurred("Uncaught unknown C++ exception"); }
72+
return 1;
73+
}
74+
5475
Tool::Tool(const char* name) : _name(name) {
5576
if ( !instance ) { instance = this; }
5677
}

tool_support/Tool.hh

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#pragma once
2020
#include "fleece/Fleece.hh"
21-
#include "Error.hh"
2221
#include "StringUtil.hh"
2322
#include "ArgumentTokenizer.hh"
2423
#include <algorithm>
@@ -45,26 +44,7 @@ class Tool {
4544

4645
static Tool* instance;
4746

48-
/** Entry point for a Tool. */
49-
virtual int main(int argc, const char* argv[]) {
50-
try {
51-
if ( getenv("CLICOLOR") ) enableColor();
52-
_toolPath = std::string(argv[0]);
53-
std::vector<std::string> args;
54-
for ( int i = 1; i < argc; ++i ) args.push_back(argv[i]);
55-
_argTokenizer.reset(args);
56-
return run();
57-
} catch ( const exit_error& x ) { return x.status; } catch ( const fail_error& ) {
58-
return 1;
59-
} catch ( const litecore::error& x ) {
60-
errorOccurred(litecore::stringprintf("Uncaught LiteCore exception: %s", x.what()));
61-
if ( x.backtrace ) x.backtrace->writeTo(std::cerr);
62-
std::cerr << std::endl;
63-
} catch ( const std::exception& x ) {
64-
errorOccurred(litecore::stringprintf("Uncaught C++ exception: %s", x.what()));
65-
} catch ( ... ) { errorOccurred("Uncaught unknown C++ exception"); }
66-
return 1;
67-
}
47+
virtual int main(int argc, const char* argv[]);
6848

6949
Tool(const Tool& parent)
7050
: _verbose(parent._verbose)

0 commit comments

Comments
 (0)