diff --git a/man/man1/gitlabvers.1 b/man/man1/gitlabvers.1 index 28d6d9c..6e6cfbf 100644 --- a/man/man1/gitlabvers.1 +++ b/man/man1/gitlabvers.1 @@ -13,6 +13,7 @@ .Nm .Fl \-version .Nm +.Op Fl a .Sh DESCRIPTION The .Nm @@ -21,6 +22,8 @@ the docker container running GitLab needs to be updated. .Pp The options are as follows: .Bl -tag -width Ds +.It Fl a, \-all +Show all versions found in GitLab's Changelog. .It Fl h, \-help Print help text and exit. .It Fl \-version diff --git a/src/main.cpp b/src/main.cpp index b2025bc..dfbd7bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,13 +16,15 @@ void print_help() { int main(int argc, char* argv[]) { try { + bool all = false; int opt_char, opt_val; struct option long_options[] = { {"help", no_argument, nullptr, 'h'}, + {"all", no_argument, nullptr, 'a'}, {"version", no_argument, &opt_val, 1}, {nullptr, 0, nullptr, 0} }; - while ((opt_char = getopt_long(argc, argv, "h", long_options, nullptr)) != -1) { + while ((opt_char = getopt_long(argc, argv, "ah", long_options, nullptr)) != -1) { std::string arg {optarg ? optarg : ""}; switch (opt_char) { case 0: { @@ -34,6 +36,9 @@ int main(int argc, char* argv[]) { } break; } + case 'a': + all = true; + break; case 'h': print_help(); return EXIT_SUCCESS; @@ -52,15 +57,14 @@ int main(int argc, char* argv[]) { } } sc::requester req; - std::istringstream text {req.get("https://gitlab.com/gitlab-org/gitlab-foss/-/raw/master/CHANGELOG.md")}; - std::string line; - for (size_t i = 0; i < 5; ++i) { - std::getline(text, line); - } - std::regex pat {R"(\d+\.\d+\.\d+)"}; - std::smatch match; - if (std::regex_search(line, match, pat)) { - std::cout << match[0] << '\n'; + std::string text {req.get("https://gitlab.com/gitlab-org/gitlab-foss/-/raw/master/CHANGELOG.md")}; + std::regex pat {R"(##\s+(\d+\.\d+\.\d+)\s+\((\d+-\d+-\d+))"}; + std::sregex_iterator beg {text.begin(), text.end(), pat}; + std::sregex_iterator end {}; + for (std::sregex_iterator i = beg; i != end; ++i) { + std::smatch match {*i}; + std::cout << match[1] << " [" << match[2] << "]\n"; + if (!all) break; } } catch (const std::exception& ex) { std::cerr << "gitlabvers: " << ex.what() << '\n';