Skip to content

Commit

Permalink
Only nag to read news when there's news to read (GothenburgBitFactory…
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche authored Nov 25, 2024
1 parent 5664182 commit a99b608
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/commands/CmdCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// cmake.h include header must come first

#include <CmdCustom.h>
#include <CmdNews.h>
#include <Context.h>
#include <Filter.h>
#include <Lexer.h>
Expand Down Expand Up @@ -222,11 +223,9 @@ 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();
auto should_nag = news_version != current_version && Context::getContext().verbose("news");
if (should_nag) {
if (CmdNews::should_nag()) {
std::ostringstream notice;
Version current_version = Version::Current();
notice << "Recently upgraded to " << current_version
<< ". "
"Please run 'task news' to read highlights about the new release.";
Expand Down
25 changes: 25 additions & 0 deletions src/commands/CmdNews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,28 @@ int CmdNews::execute(std::string& output) {

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;
}
2 changes: 2 additions & 0 deletions src/commands/CmdNews.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class CmdNews : public Command {
public:
CmdNews();
int execute(std::string&);

static bool should_nag();
};

#endif
Expand Down

0 comments on commit a99b608

Please sign in to comment.