Add -a/--all option to show all versions

This commit is contained in:
2025-01-06 10:31:05 +01:00
parent d0c1fa1740
commit f63c279fb4
2 changed files with 17 additions and 10 deletions

View File

@@ -13,6 +13,7 @@
.Nm .Nm
.Fl \-version .Fl \-version
.Nm .Nm
.Op Fl a
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm .Nm
@@ -21,6 +22,8 @@ the docker container running GitLab needs to be updated.
.Pp .Pp
The options are as follows: The options are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl a, \-all
Show all versions found in GitLab's Changelog.
.It Fl h, \-help .It Fl h, \-help
Print help text and exit. Print help text and exit.
.It Fl \-version .It Fl \-version

View File

@@ -16,13 +16,15 @@ void print_help() {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
try { try {
bool all = false;
int opt_char, opt_val; int opt_char, opt_val;
struct option long_options[] = { struct option long_options[] = {
{"help", no_argument, nullptr, 'h'}, {"help", no_argument, nullptr, 'h'},
{"all", no_argument, nullptr, 'a'},
{"version", no_argument, &opt_val, 1}, {"version", no_argument, &opt_val, 1},
{nullptr, 0, nullptr, 0} {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 : ""}; std::string arg {optarg ? optarg : ""};
switch (opt_char) { switch (opt_char) {
case 0: { case 0: {
@@ -34,6 +36,9 @@ int main(int argc, char* argv[]) {
} }
break; break;
} }
case 'a':
all = true;
break;
case 'h': case 'h':
print_help(); print_help();
return EXIT_SUCCESS; return EXIT_SUCCESS;
@@ -52,15 +57,14 @@ int main(int argc, char* argv[]) {
} }
} }
sc::requester req; sc::requester req;
std::istringstream text {req.get("https://gitlab.com/gitlab-org/gitlab-foss/-/raw/master/CHANGELOG.md")}; std::string text {req.get("https://gitlab.com/gitlab-org/gitlab-foss/-/raw/master/CHANGELOG.md")};
std::string line; std::regex pat {R"(##\s+(\d+\.\d+\.\d+)\s+\((\d+-\d+-\d+))"};
for (size_t i = 0; i < 5; ++i) { std::sregex_iterator beg {text.begin(), text.end(), pat};
std::getline(text, line); std::sregex_iterator end {};
} for (std::sregex_iterator i = beg; i != end; ++i) {
std::regex pat {R"(\d+\.\d+\.\d+)"}; std::smatch match {*i};
std::smatch match; std::cout << match[1] << " [" << match[2] << "]\n";
if (std::regex_search(line, match, pat)) { if (!all) break;
std::cout << match[0] << '\n';
} }
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
std::cerr << "gitlabvers: " << ex.what() << '\n'; std::cerr << "gitlabvers: " << ex.what() << '\n';