# # # patch "Makefile.am" # from [4a87794776b9ceb07c5b2aeedc89f9353160bee2] # to [175ae478fedc5c9ea2b21acfc45cc2290a393b5f] # # patch "automate.cc" # from [d1bd5147b257f8621658e43ae74438b050cc3753] # to [3ded2ab763b89f71ec4467df23e83654be5768ac] # # patch "cmd.cc" # from [3ba2069fb848fe8f6e1a7237d512c940919dd308] # to [b9a168907c2f31f809c83de113c1c3c8f13f3af3] # # patch "cmd_automate.cc" # from [ed92af7bbe757d262e38549cd4bf84ad875eb747] # to [7ce00e4e80ddc115bb564e50d66ebb66af548343] # # patch "options_list.hh" # from [fd76b9934d9aafaf6d3a22a7422708d39089a088] # to [191d0c149c9774b250ac0ce56e2c1a016a0bce0c] # # patch "sanity.cc" # from [a8836cf95d078e7230265448bc755d278c1e1ec6] # to [d4a7256e2215057ca0fa1a0a25d63c429c8622c4] # # patch "sanity.hh" # from [b1b2f96e89fbcdc0028b41416370704a9d8b0cf9] # to [6f2f5e7964abbdb8eed0d1e38d221b722741617e] # # patch "ui.cc" # from [fa29365937f4748f3b5c019e2af9e4a55a973d2a] # to [8b4da1b636b654629b9d54e221825670b5f9a5bd] # # patch "ui.hh" # from [4fa5387d6dfed9dd268b7856e0561b6c4158fdfa] # to [8c46e815f378359bb3756605ad3771ee155089a7] # ============================================================ --- Makefile.am 4a87794776b9ceb07c5b2aeedc89f9353160bee2 +++ Makefile.am 175ae478fedc5c9ea2b21acfc45cc2290a393b5f @@ -116,6 +116,7 @@ MOST_SOURCES = \ netio.hh gettext.h \ package_revision.cc package_full_revision.cc \ option.cc option.hh options.cc options.hh options_list.hh \ + options_applicator.hh options_applicator.cc \ option_reset_info.hh \ specialized_lexical_cast.cc lexical_cast.hh \ parallel_iter.hh safe_map.hh pch.hh current_exception.hh ============================================================ --- automate.cc d1bd5147b257f8621658e43ae74438b050cc3753 +++ automate.cc 3ded2ab763b89f71ec4467df23e83654be5768ac @@ -32,6 +32,7 @@ #include "keys.hh" #include "key_store.hh" #include "file_io.hh" +#include "options_applicator.hh" #include "packet.hh" #include "restrictions.hh" #include "revision.hh" @@ -2402,7 +2403,7 @@ automate_stdio_shared_setup(app_state & // set a fixed ticker type regardless what the user wants to // see, because anything else would screw the stdio-encoded output - ui.set_tick_write_stdio(); + app.opts.ticker = "stdio"; } std::pair automate_stdio_helpers:: @@ -2439,6 +2440,7 @@ automate_stdio_shared_body(app_state & a pre_exec_fn(id); try { + options_applicator oa(app.opts, options_applicator::for_automate_subcmd); // as soon as a command requires a workspace, this is set to true workspace::used = false; ============================================================ --- cmd.cc 3ba2069fb848fe8f6e1a7237d512c940919dd308 +++ cmd.cc b9a168907c2f31f809c83de113c1c3c8f13f3af3 @@ -13,6 +13,7 @@ #include "lua.hh" #include "app_state.hh" +#include "options_applicator.hh" #include "work.hh" #include "ui.hh" #include "mt_version.hh" @@ -201,6 +202,10 @@ namespace commands { reapply_options(app, cmd, ident); + // intentional leak + // we don't want the options to be reset, so don't destruct this + new options_applicator(app.opts, options_applicator::for_primary_cmd); + cmd->exec(app, ident, args); } ============================================================ --- cmd_automate.cc ed92af7bbe757d262e38549cd4bf84ad875eb747 +++ cmd_automate.cc 7ce00e4e80ddc115bb564e50d66ebb66af548343 @@ -19,6 +19,7 @@ #include "automate_ostream.hh" #include "automate_reader.hh" #include "automate_stdio_helpers.hh" +#include "options_applicator.hh" #include "ui.hh" #include "lua.hh" #include "lua_hooks.hh" @@ -382,6 +383,9 @@ LUAEXT(mtn_automate, ) = dynamic_cast< commands::automate const * >(cmd); I(acmd); + + options_applicator oa(app_p->opts, options_applicator::for_automate_subcmd); + // as soon as a command requires a workspace, this is set to true workspace::used = false; ============================================================ --- options_list.hh fd76b9934d9aafaf6d3a22a7422708d39089a088 +++ options_list.hh 191d0c149c9774b250ac0ce56e2c1a016a0bce0c @@ -604,26 +604,41 @@ SIMPLE_OPTION(pidfile, "pid-file/no-pid- SIMPLE_OPTION(pidfile, "pid-file/no-pid-file", system_path, gettext_noop("record process id of server")) -GOPT(quiet, "quiet", bool, false, - gettext_noop("suppress verbose, informational and progress messages")) +GLOBAL_SIMPLE_OPTION(extra_rcfiles, "rcfile/clear-rcfiles", args_vector, + gettext_noop("load extra rc file")) + +OPTSET(verbosity) +OPTSET_REL(globals, verbosity) +OPTVAR(verbosity, int, verbosity, 0) +OPTION(verbosity, set_verbosity, true, "verbosity", + gettext_noop("set verbosity level: 0 is default; 1 is verbose; " + "-1 is hide tickers and progress messages; -2 is also hide warnings")) #ifdef option_bodies { - quiet = true; - global_sanity.set_quiet(); - ui.set_tick_write_nothing(); + verbosity = boost::lexical_cast(arg); } #endif +OPTION(verbosity, inc_verbosity, false, "v", + gettext_noop("increase verbosity level by one")) +#ifdef option_bodies +{ + ++verbosity; +} +#endif -GLOBAL_SIMPLE_OPTION(extra_rcfiles, "rcfile/clear-rcfiles", args_vector, - gettext_noop("load extra rc file")) +OPTION(verbosity, quiet, false, "quiet", + gettext_noop("suppress verbose, informational and progress messages")) +#ifdef option_bodies +{ + verbosity = -1; +} +#endif -GOPT(reallyquiet, "reallyquiet", bool, false, +OPTION(verbosity, reallyquiet, false, "reallyquiet", gettext_noop("suppress warning, verbose, informational and progress messages")) #ifdef option_bodies { - reallyquiet = true; - global_sanity.set_reallyquiet(); - ui.set_tick_write_nothing(); + verbosity = -2; } #endif @@ -632,7 +647,6 @@ GOPT(timestamps, "timestamps", bool, fal #ifdef option_bodies { timestamps = true; - ui.enable_timestamps(); } #endif @@ -664,13 +678,9 @@ GOPT(ticker, "ticker", std::string, , #ifdef option_bodies { ticker = arg; - if (ticker == "none" || global_sanity.quiet_p()) - ui.set_tick_write_nothing(); - else if (ticker == "dot") - ui.set_tick_write_dot(); - else if (ticker == "count") - ui.set_tick_write_count(); - else + if (ticker != "none" && + ticker != "dot" && + ticker != "count") throw bad_arg_internal(F("argument must be 'none', 'dot', or 'count'").str()); } #endif ============================================================ --- sanity.cc a8836cf95d078e7230265448bc755d278c1e1ec6 +++ sanity.cc d4a7256e2215057ca0fa1a0a25d63c429c8622c4 @@ -66,9 +66,7 @@ struct sanity::impl struct sanity::impl { - bool debug; - bool quiet; - bool reallyquiet; + int verbosity; boost::circular_buffer logbuf; std::string real_prog_name; std::string filename; @@ -80,7 +78,7 @@ struct sanity::impl void *out_of_band_opaque; impl() : - debug(false), quiet(false), reallyquiet(false), logbuf(0xffff), + verbosity(0), logbuf(0xffff), already_dumping(false), out_of_band_function(0), out_of_band_opaque(0) {} }; @@ -171,41 +169,37 @@ sanity::dump_buffer() "(maybe you want --debug or --dump?)"); } -void -sanity::set_debug() +int +sanity::set_verbosity(int level) { I(imp); - imp->quiet = false; - imp->reallyquiet = false; - imp->debug = true; + int ret = imp->verbosity; + imp->verbosity = level; - // it is possible that some pre-setting-of-debug data - // accumulated in the log buffer (during earlier option processing) - // so we will dump it now - ostringstream oss; - vector lines; - copy(imp->logbuf.begin(), imp->logbuf.end(), ostream_iterator(oss)); - split_into_lines(oss.str(), lines); - for (vector::const_iterator i = lines.begin(); i != lines.end(); ++i) - inform_log((*i) + "\n"); + if (level >= 2) + { + // it is possible that some pre-setting-of-debug data + // accumulated in the log buffer (during earlier option processing) + // so we will dump it now + ostringstream oss; + vector lines; + copy(imp->logbuf.begin(), imp->logbuf.end(), ostream_iterator(oss)); + split_into_lines(oss.str(), lines); + for (vector::const_iterator i = lines.begin(); i != lines.end(); ++i) + inform_log((*i) + "\n"); + } + return ret; } - void -sanity::set_quiet() +sanity::set_debug() { - I(imp); - imp->debug = false; - imp->quiet = true; - imp->reallyquiet = false; + set_verbosity(2); } - -void -sanity::set_reallyquiet() +int +sanity::get_verbosity() const { I(imp); - imp->debug = false; - imp->quiet = true; - imp->reallyquiet = true; + return imp->verbosity; } void @@ -242,27 +236,9 @@ sanity::debug_p() if (!imp) throw std::logic_error("sanity::debug_p called " "before sanity::initialize"); - return imp->debug; + return imp->verbosity >= 2; } -bool -sanity::quiet_p() -{ - if (!imp) - throw std::logic_error("sanity::quiet_p called " - "before sanity::initialize"); - return imp->quiet; -} - -bool -sanity::reallyquiet_p() -{ - if (!imp) - throw std::logic_error("sanity::reallyquiet_p called " - "before sanity::initialize"); - return imp->reallyquiet; -} - void sanity::log(plain_format const & fmt, char const * file, int line) @@ -377,7 +353,7 @@ sanity::index_failure(char const * vec_e if (!imp) throw std::logic_error("sanity::index_failure occured " "before sanity::initialize"); - if (imp->debug) + if (debug_p()) log(FL(pattern) % file % line % idx_expr % idx % vec_expr % sz, file, line); gasp(); @@ -446,7 +422,7 @@ sanity::gasp() } imp->gasp_dump = out.str(); L(FL("finished saving work set")); - if (imp->debug) + if (debug_p()) { inform_log("contents of work set:"); inform_log(imp->gasp_dump); ============================================================ --- sanity.hh b1b2f96e89fbcdc0028b41416370704a9d8b0cf9 +++ sanity.hh 6f2f5e7964abbdb8eed0d1e38d221b722741617e @@ -63,15 +63,18 @@ struct sanity { virtual ~sanity(); virtual void initialize(int, char **, char const *); void dump_buffer(); - void set_debug(); - void set_quiet(); - void set_reallyquiet(); + int set_verbosity(int level); + int get_verbosity() const; + void set_debug(); // wrapper on set_verbosity // This takes a bare std::string because we don't want to expose vocab.hh // or paths.hh here. void set_dump_path(std::string const & path); // set out of band handler (e.g. for automate stdio) - void set_out_of_band_handler(void (*out_of_band_function)(char channel, std::string const& text, void *opaque)=NULL, void *opaque_data=NULL); + void set_out_of_band_handler(void (*out_of_band_function)(char channel, + std::string const& text, + void *opaque)=NULL, + void *opaque_data=NULL); // if such an out of band handler is set, this directly writes to it bool maybe_write_to_out_of_band_handler(char channel, std::string const& str); @@ -80,12 +83,6 @@ struct sanity { // expensive logging if it's off. bool debug_p(); - // ??? --quiet overrides any --ticker= setting if both are on the - // command line (and needs to look at this to do so). - bool quiet_p(); - - bool reallyquiet_p(); - void log(plain_format const & fmt, char const * file, int line); void progress(i18n_format const & fmt, @@ -331,7 +328,7 @@ do { \ // normally like to see some indication of progress of #define P(fmt) \ do { \ - if (!global_sanity.quiet_p()) \ + if (global_sanity.get_verbosity() > -1) \ global_sanity.progress(fmt, __FILE__, __LINE__); \ } while (0) @@ -339,7 +336,7 @@ do { \ // they are only issued once and are prefixed with "warning: " #define W(fmt) \ do { \ - if (!global_sanity.reallyquiet_p()) \ + if (global_sanity.get_verbosity() > -2) \ global_sanity.warning(fmt, __FILE__, __LINE__); \ } while (0) ============================================================ --- ui.cc fa29365937f4748f3b5c019e2af9e4a55a973d2a +++ ui.cc 8b4da1b636b654629b9d54e221825670b5f9a5bd @@ -605,7 +605,27 @@ user_interface::set_tick_write_nothing() tick_type = none; } +user_interface::ticker_type +user_interface::set_ticker_type(user_interface::ticker_type type) +{ + ticker_type ret = tick_type; + switch (type) + { + case count: set_tick_write_count(); break; + case dot: set_tick_write_dot(); break; + case stdio: set_tick_write_stdio(); break; + case none: set_tick_write_nothing(); break; + } + return ret; +} +user_interface::ticker_type +user_interface::get_ticker_type() const +{ + return tick_type; +} + + void user_interface::write_ticks() { @@ -1013,10 +1033,12 @@ user_interface::inform_usage(usage const commands::explain_usage(u.which, opts.show_hidden_commands, usage_stream); } -void -user_interface::enable_timestamps() +bool +user_interface::enable_timestamps(bool enable) { - timestamps_enabled = true; + bool ret = timestamps_enabled; + timestamps_enabled = enable; + return ret; } // Local Variables: ============================================================ --- ui.hh 4fa5387d6dfed9dd268b7856e0561b6c4158fdfa +++ ui.hh 8c46e815f378359bb3756605ad3771ee155089a7 @@ -65,13 +65,18 @@ public: int fatal_exception(std::exception const & ex); int fatal_exception(); void set_tick_trailer(std::string const & trailer); + + enum ticker_type { count=1, dot, stdio, none }; void set_tick_write_dot(); void set_tick_write_count(); void set_tick_write_stdio(); void set_tick_write_nothing(); + ticker_type set_ticker_type(ticker_type type); + ticker_type get_ticker_type() const; + void ensure_clean_line(); void redirect_log_to(system_path const & filename); - void enable_timestamps(); + bool enable_timestamps(bool enable); std::string output_prefix(); @@ -82,7 +87,7 @@ private: struct impl; impl * imp; bool timestamps_enabled; - enum ticker_type { count=1, dot, stdio, none } tick_type; + ticker_type tick_type; friend struct ticker; friend struct tick_write_count;