From fd78974020e23679e9e810cf01dc5c8f3012bb8a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 13 May 2016 16:59:09 +0200 Subject: show globalerrors before asking for confirmation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Errors cause a kind of automatic no already, but warnings and notices are only displayed at the end of the apt execution even through they could effect the choice of saying yes/no to questions: E.g. if a configuration (file) was ignored you wanted to have an effect or if an external solver you used generated warnings suggesting that the solution might be valid, but bogus non-the-less and similar things. Note that this only moves those messages up to the question if the answer is interactive – not if e.g. -y is used or no question is asked at all so this has an effect only on interactive usage of apt(-get), not script who might be parsing apt output. --- apt-private/private-output.cc | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'apt-private/private-output.cc') diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 458d78dc4..301aa5519 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -650,8 +650,21 @@ void Stats(ostream &out,pkgDepCache &Dep) // YnPrompt - Yes No Prompt. /*{{{*/ // --------------------------------------------------------------------- /* Returns true on a Yes.*/ -bool YnPrompt(bool Default) +bool YnPrompt(char const * const Question, bool Default) { + auto const AssumeYes = _config->FindB("APT::Get::Assume-Yes",false); + auto const AssumeNo = _config->FindB("APT::Get::Assume-No",false); + // if we ask interactively, show warnings/notices before the question + if (AssumeYes == false && AssumeNo == false) + { + if (_config->FindI("quiet",0) > 0) + _error->DumpErrors(c2out); + else + _error->DumpErrors(c2out, GlobalError::DEBUG); + } + + c2out << Question << std::flush; + /* nl_langinfo does not support LANGUAGE setting, so we unset it here to have the help-message (hopefully) match the expected characters */ char * language = getenv("LANGUAGE"); @@ -679,13 +692,13 @@ bool YnPrompt(bool Default) free(language); } - if (_config->FindB("APT::Get::Assume-Yes",false) == true) + if (AssumeYes) { // TRANSLATOR: "Yes" answer printed for a yes/no question if --assume-yes is set c1out << _("Y") << std::endl; return true; } - else if (_config->FindB("APT::Get::Assume-No",false) == true) + else if (AssumeNo) { // TRANSLATOR: "No" answer printed for a yes/no question if --assume-no is set c1out << _("N") << std::endl; @@ -722,8 +735,14 @@ bool YnPrompt(bool Default) // AnalPrompt - Annoying Yes No Prompt. /*{{{*/ // --------------------------------------------------------------------- /* Returns true on a Yes.*/ -bool AnalPrompt(const char *Text) +bool AnalPrompt(std::string const &Question, const char *Text) { + if (_config->FindI("quiet",0) > 0) + _error->DumpErrors(c2out); + else + _error->DumpErrors(c2out, GlobalError::DEBUG); + c2out << Question << std::flush; + char Buf[1024]; std::cin.getline(Buf,sizeof(Buf)); if (strcmp(Buf,Text) == 0) -- cgit v1.2.3