Adding clang-format, and reformating all sourcecode

This commit is contained in:
Ian Roddis
2021-09-21 09:41:11 -03:00
parent 39d5ae08be
commit 288ce28d29
36 changed files with 3355 additions and 2802 deletions

View File

@@ -1,78 +1,77 @@
#include <iostream>
#include <fstream>
#include <filesystem>
#include <argparse.hpp>
#include <pistache/client.h>
#include <rapidjson/document.h>
#include <argparse.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>
namespace rj = rapidjson;
Pistache::Http::Response
REQUEST(std::string url, std::string payload = "") {
Pistache::Http::Experimental::Client client;
client.init();
Pistache::Http::Response response;
auto reqSpec = (payload.empty() ? client.get(url) : client.post(url));
reqSpec.timeout(std::chrono::seconds(2));
if (!payload.empty()) {
reqSpec.body(payload);
}
auto request = reqSpec.send();
bool ok = false, error = false;
std::string msg;
request.then(
[&](Pistache::Http::Response rsp) {
ok = true;
response = rsp;
},
[&](std::exception_ptr ptr) {
error = true;
try {
std::rethrow_exception(ptr);
} catch (std::exception &e) {
msg = e.what();
}
}
);
Pistache::Http::Response REQUEST(std::string url, std::string payload = "")
{
Pistache::Http::Experimental::Client client;
client.init();
Pistache::Http::Response response;
auto reqSpec = (payload.empty() ? client.get(url) : client.post(url));
reqSpec.timeout(std::chrono::seconds(2));
if (!payload.empty()) {
reqSpec.body(payload);
}
auto request = reqSpec.send();
bool ok = false, error = false;
std::string msg;
request.then(
[&](Pistache::Http::Response rsp) {
ok = true;
response = rsp;
},
[&](std::exception_ptr ptr) {
error = true;
try {
std::rethrow_exception(ptr);
}
catch (std::exception &e) {
msg = e.what();
}
});
Pistache::Async::Barrier<Pistache::Http::Response> barrier(request);
barrier.wait_for(std::chrono::seconds(2));
client.shutdown();
if (error) {
throw std::runtime_error(msg);
}
return response;
Pistache::Async::Barrier<Pistache::Http::Response> barrier(request);
barrier.wait_for(std::chrono::seconds(2));
client.shutdown();
if (error) {
throw std::runtime_error(msg);
}
return response;
}
int main(int argc, char **argv) {
argparse::ArgumentParser args("Daggy Client");
int main(int argc, char **argv)
{
argparse::ArgumentParser args("Daggy Client");
args.add_argument("-v", "--verbose")
.default_value(false)
.implicit_value(true);
args.add_argument("--url")
.help("base URL of server")
.default_value("http://localhost:2503");
args.add_argument("--sync")
.default_value(false)
.implicit_value(true)
.help("Poll for job to complete");
args.add_argument("--action")
.help("Number of tasks to run concurrently")
.default_value(30)
.action([](const std::string &value) { return std::stoull(value); });
args.add_argument("-v", "--verbose")
.default_value(false)
.implicit_value(true);
args.add_argument("--url")
.help("base URL of server")
.default_value("http://localhost:2503");
args.add_argument("--sync").default_value(false).implicit_value(true).help(
"Poll for job to complete");
args.add_argument("--action")
.help("Number of tasks to run concurrently")
.default_value(30)
.action([](const std::string &value) { return std::stoull(value); });
try {
args.parse_args(argc, argv);
} catch (std::exception &e) {
std::cout << "Error: " << e.what() << std::endl;
std::cout << args;
exit(1);
}
try {
args.parse_args(argc, argv);
}
catch (std::exception &e) {
std::cout << "Error: " << e.what() << std::endl;
std::cout << args;
exit(1);
}
std::string baseURL = args.get<std::string>("--url");
std::string baseURL = args.get<std::string>("--url");
auto response = REQUEST(baseURL + "/ready");
auto response = REQUEST(baseURL + "/ready");
}