File tree Expand file tree Collapse file tree 2 files changed +22
-21
lines changed Expand file tree Collapse file tree 2 files changed +22
-21
lines changed Original file line number Diff line number Diff line change 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
5253Tool* 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+
5475Tool::Tool (const char * name) : _name(name) {
5576 if ( !instance ) { instance = this ; }
5677}
Original file line number Diff line number Diff line change 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)
You can’t perform that action at this time.
0 commit comments