From c47e03c87ca5adbb6f93d6899e83af83c1f712bc Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Thu, 15 May 2025 21:38:51 +0200 Subject: [PATCH] Reverse order of lines when using -a option Now the most recent come at the end, which is more convenient when output is done to a terminal. --- src/main.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2aa1a7e..bd8ca55 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include #include "version.hpp" @@ -60,11 +62,17 @@ int main(int argc, char* argv[]) { std::regex pat {R"(^##\s+(\d+\.\d+\.\d+)\s+\((\d+-\d+-\d+))", std::regex::multiline}; std::sregex_iterator beg {text.begin(), text.end(), pat}; std::sregex_iterator end {}; + std::vector lines; for (std::sregex_iterator i = beg; i != end; ++i) { std::smatch match {*i}; - std::cout << match[1] << " [" << match[2] << "]\n"; + std::ostringstream oss; + oss << match[1] << " [" << match[2] << "]\n"; + lines.insert(lines.begin(), oss.str()); if (!all) break; } + for (const std::string& line : lines) { + std::cout << line; + } } catch (const std::exception& ex) { std::cerr << "gitlabvers: " << ex.what() << '\n'; return EXIT_FAILURE;