mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-09-09 09:40:37 +02:00
Only nag to read news when there's news to read (#3699)
This commit is contained in:
parent
5664182f5e
commit
a99b6084e8
3 changed files with 30 additions and 4 deletions
|
@ -28,6 +28,7 @@
|
||||||
// cmake.h include header must come first
|
// cmake.h include header must come first
|
||||||
|
|
||||||
#include <CmdCustom.h>
|
#include <CmdCustom.h>
|
||||||
|
#include <CmdNews.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Filter.h>
|
#include <Filter.h>
|
||||||
#include <Lexer.h>
|
#include <Lexer.h>
|
||||||
|
@ -222,11 +223,9 @@ int CmdCustom::execute(std::string& output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inform user about the new release highlights if not presented yet
|
// Inform user about the new release highlights if not presented yet
|
||||||
Version news_version(Context::getContext().config.get("news.version"));
|
if (CmdNews::should_nag()) {
|
||||||
Version current_version = Version::Current();
|
|
||||||
auto should_nag = news_version != current_version && Context::getContext().verbose("news");
|
|
||||||
if (should_nag) {
|
|
||||||
std::ostringstream notice;
|
std::ostringstream notice;
|
||||||
|
Version current_version = Version::Current();
|
||||||
notice << "Recently upgraded to " << current_version
|
notice << "Recently upgraded to " << current_version
|
||||||
<< ". "
|
<< ". "
|
||||||
"Please run 'task news' to read highlights about the new release.";
|
"Please run 'task news' to read highlights about the new release.";
|
||||||
|
|
|
@ -615,3 +615,28 @@ int CmdNews::execute(std::string& output) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CmdNews::should_nag() {
|
||||||
|
if (!Context::getContext().verbose("news")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Version news_version(Context::getContext().config.get("news.version"));
|
||||||
|
if (!news_version.is_valid()) news_version = Version("2.6.0");
|
||||||
|
|
||||||
|
Version current_version = Version::Current();
|
||||||
|
|
||||||
|
if (news_version == current_version) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if there are actually any interesting news items to show.
|
||||||
|
std::vector<NewsItem> items = NewsItem::all();
|
||||||
|
for (auto& item : items) {
|
||||||
|
if (item._version > news_version) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -63,6 +63,8 @@ class CmdNews : public Command {
|
||||||
public:
|
public:
|
||||||
CmdNews();
|
CmdNews();
|
||||||
int execute(std::string&);
|
int execute(std::string&);
|
||||||
|
|
||||||
|
static bool should_nag();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue