mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-09-07 21:07:20 +02:00
Make task news
nag configurable and deterministic (#3567)
This patch fixes #3497.
This commit is contained in:
parent
9dde68f918
commit
9c49863795
5 changed files with 84 additions and 20 deletions
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include <cmake.h>
|
||||
#include <CmdCustom.h>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
@ -254,23 +253,16 @@ int CmdCustom::execute (std::string& output)
|
|||
// Inform user about the new release highlights if not presented yet
|
||||
Version news_version(Context::getContext ().config.get ("news.version"));
|
||||
Version current_version = Version::Current();
|
||||
if (news_version != current_version)
|
||||
auto should_nag = news_version != current_version && Context::getContext ().verbose ("news");
|
||||
if (should_nag)
|
||||
{
|
||||
std::random_device device;
|
||||
std::mt19937 random_generator(device());
|
||||
std::uniform_int_distribution<std::mt19937::result_type> twentyfive_percent(1, 4);
|
||||
|
||||
// 25% chance to display the message.
|
||||
if (twentyfive_percent(random_generator) == 4)
|
||||
{
|
||||
std::ostringstream notice;
|
||||
notice << "Recently upgraded to " << current_version << ". "
|
||||
"Please run 'task news' to read highlights about the new release.";
|
||||
if (Context::getContext ().verbose ("footnote"))
|
||||
Context::getContext ().footnote (notice.str());
|
||||
else if (Context::getContext ().verbose ("header"))
|
||||
Context::getContext ().header (notice.str());
|
||||
}
|
||||
std::ostringstream notice;
|
||||
notice << "Recently upgraded to " << current_version << ". "
|
||||
"Please run 'task news' to read highlights about the new release.";
|
||||
if (Context::getContext ().verbose ("footnote"))
|
||||
Context::getContext ().footnote (notice.str());
|
||||
else if (Context::getContext ().verbose ("header"))
|
||||
Context::getContext ().header (notice.str());
|
||||
}
|
||||
|
||||
std::string location = (Context::getContext ().data_dir);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue