@@ -21,9 +21,6 @@ command_line_app_t::command_line_app_t(std::string app_description)
2121
2222 add_flag (" -h,--help" , " Print this help message and exit." );
2323 add_flag (" -V,--version" , " Show version and exit." );
24-
25- init_database_options ();
26- init_logging_options ();
2724}
2825
2926bool command_line_app_t::want_help () const { return count (" --help" ); }
@@ -75,7 +72,7 @@ void command_line_app_t::init_database_options()
7572 ->group (" Database options" );
7673}
7774
78- void command_line_app_t::init_logging_options ()
75+ void command_line_app_t::init_logging_options (bool with_progress, bool with_sql )
7976{
8077 static std::map<std::string, log_level> const log_levels_map{
8178 {" debug" , log_level::debug},
@@ -97,31 +94,36 @@ void command_line_app_t::init_logging_options()
9794 ->option_text (" LEVEL" )
9895 ->group (" Logging options" );
9996
100- add_option_function<std::string>(
101- " --log-progress" ,
102- [&](std::string const &arg) {
103- if (arg == " true" ) {
104- get_logger ().enable_progress ();
105- } else if (arg == " false" ) {
106- get_logger ().disable_progress ();
107- } else if (arg == " auto" ) {
108- get_logger ().auto_progress ();
109- } else {
110- throw fmt_error (" Unknown value for --log-progress option: {}" ,
111- arg);
112- }
113- })
114- ->description (
115- " Log progress to console ('true', 'false', 'auto' (default))." )
116- ->option_text (" PROGRESS" )
117- ->group (" Logging options" );
118-
119- add_flag_function (" --log-sql" , [](int64_t ) { get_logger ().enable_sql (); })
120- ->description (" Enable logging of SQL commands for debugging." )
121- ->group (" Logging options" );
122-
123- add_flag_function (" --log-sql-data" ,
124- [](int64_t ) { get_logger ().enable_sql_data (); })
125- ->description (" Enable logging of all data added to the database." )
126- ->group (" Logging options" );
97+ if (with_progress) {
98+ add_option_function<std::string>(
99+ " --log-progress" ,
100+ [&](std::string const &arg) {
101+ if (arg == " true" ) {
102+ get_logger ().enable_progress ();
103+ } else if (arg == " false" ) {
104+ get_logger ().disable_progress ();
105+ } else if (arg == " auto" ) {
106+ get_logger ().auto_progress ();
107+ } else {
108+ throw fmt_error (
109+ " Unknown value for --log-progress option: {}" , arg);
110+ }
111+ })
112+ ->description (
113+ " Log progress to console ('true', 'false', 'auto' (default))." )
114+ ->option_text (" PROGRESS" )
115+ ->group (" Logging options" );
116+ }
117+
118+ if (with_sql) {
119+ add_flag_function (" --log-sql" ,
120+ [](int64_t ) { get_logger ().enable_sql (); })
121+ ->description (" Enable logging of SQL commands for debugging." )
122+ ->group (" Logging options" );
123+
124+ add_flag_function (" --log-sql-data" ,
125+ [](int64_t ) { get_logger ().enable_sql_data (); })
126+ ->description (" Enable logging of all data added to the database." )
127+ ->group (" Logging options" );
128+ }
127129}
0 commit comments