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