Add 'using namespace std' for readability

This commit is contained in:
2025-05-16 12:45:40 +02:00
parent 99d7f3bfa2
commit 749652494e

View File

@@ -8,10 +8,12 @@
#include <libscrequest.hpp> #include <libscrequest.hpp>
#include "version.hpp" #include "version.hpp"
using namespace std;
void print_help() { void print_help() {
std::cout << "usage: gitlabvers [-h|--version]\n"; cout << "usage: gitlabvers [-h|--version]\n";
std::cout << " -h, --help show this help text and exit\n"; cout << " -h, --help show this help text and exit\n";
std::cout << " --version show version number and exit\n"; cout << " --version show version number and exit\n";
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
@@ -25,13 +27,13 @@ int main(int argc, char* argv[]) {
{nullptr, 0, nullptr, 0} {nullptr, 0, nullptr, 0}
}; };
while ((opt_char = getopt_long(argc, argv, "ah", long_options, nullptr)) != -1) { while ((opt_char = getopt_long(argc, argv, "ah", long_options, nullptr)) != -1) {
std::string arg {optarg ? optarg : ""}; string arg {optarg ? optarg : ""};
switch (opt_char) { switch (opt_char) {
case 0: { case 0: {
// handle long-only options here // handle long-only options here
switch (opt_val) { switch (opt_val) {
case 1: case 1:
std::cout << gitlabvers_version() << std::endl; cout << gitlabvers_version() << endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
break; break;
@@ -43,7 +45,7 @@ int main(int argc, char* argv[]) {
print_help(); print_help();
return EXIT_SUCCESS; return EXIT_SUCCESS;
case '?': case '?':
throw std::runtime_error("unrecognized option"); throw runtime_error("unrecognized option");
} }
} }
if (optind == argc) { if (optind == argc) {
@@ -52,27 +54,27 @@ int main(int argc, char* argv[]) {
for (int i = optind; i < argc; ++i) { for (int i = optind; i < argc; ++i) {
try { try {
// process file argv[i] // process file argv[i]
} catch (const std::runtime_error& ex) { } catch (const runtime_error& ex) {
std::cerr << "gitlabvers: " << ex.what() << '\n'; cerr << "gitlabvers: " << ex.what() << '\n';
} }
} }
sc::requester req; sc::requester req;
std::string text {req.get("https://gitlab.com/gitlab-org/gitlab-foss/-/raw/master/CHANGELOG.md")}; 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::regex::multiline}; regex pat {R"(^##\s+(\d+\.\d+\.\d+)\s+\((\d+-\d+-\d+))", regex::multiline};
std::sregex_iterator beg {text.begin(), text.end(), pat}; sregex_iterator beg {text.begin(), text.end(), pat};
std::sregex_iterator end {}; sregex_iterator end {};
std::vector<std::string> lines; vector<string> lines;
for (std::sregex_iterator i = beg; i != end; ++i) { for (sregex_iterator i = beg; i != end; ++i) {
std::smatch match {*i}; smatch match {*i};
std::string line = std::string(match[1]) + " [" + std::string(match[2]) + "]\n"; string line = string(match[1]) + " [" + string(match[2]) + "]\n";
lines.push_back(line); lines.push_back(line);
if (!all) break; if (!all) break;
} }
for (auto it = lines.rbegin(); it != lines.rend(); ++it) { for (auto it = lines.rbegin(); it != lines.rend(); ++it) {
std::cout << *it; cout << *it;
} }
} catch (const std::exception& ex) { } catch (const exception& ex) {
std::cerr << "gitlabvers: " << ex.what() << '\n'; cerr << "gitlabvers: " << ex.what() << '\n';
return EXIT_FAILURE; return EXIT_FAILURE;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;