2020-09-01 16:12:41 +02:00
|
|
|
//
|
|
|
|
// main.cpp
|
|
|
|
// curly
|
|
|
|
//
|
|
|
|
// Created by Bob Polis at 2020-09-01
|
|
|
|
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <libsclogging.hpp>
|
2020-09-02 09:53:22 +02:00
|
|
|
#include "requester.hpp"
|
2020-09-01 16:12:41 +02:00
|
|
|
|
|
|
|
sc::logger logger {"curly", sc::loglevel::info};
|
|
|
|
|
|
|
|
void print_help() {
|
|
|
|
std::cout << "usage: curly [-h|--version]\n";
|
|
|
|
std::cout << " -h, --help show this help text and exit\n";
|
|
|
|
std::cout << " --version show version number and exit\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_version() {
|
|
|
|
std::cout << "curly version 1.0\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char * argv[]) {
|
|
|
|
try {
|
|
|
|
int opt_char, opt_val;
|
|
|
|
struct option long_options[] = {
|
|
|
|
{"help", no_argument, nullptr, 'h'},
|
|
|
|
{"version", no_argument, &opt_val, 1},
|
|
|
|
{nullptr, 0, nullptr, 0}
|
|
|
|
};
|
|
|
|
while ((opt_char = getopt_long(argc, const_cast<char* const *>(argv), "h", long_options, nullptr)) != -1) {
|
|
|
|
std::string arg {optarg ? optarg : ""};
|
|
|
|
switch (opt_char) {
|
|
|
|
case 0: {
|
|
|
|
// handle long-only options here
|
|
|
|
switch (opt_val) {
|
|
|
|
case 1:
|
|
|
|
print_version();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'h':
|
|
|
|
print_help();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
case '?':
|
|
|
|
throw std::runtime_error("unrecognized option");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (optind == argc) {
|
|
|
|
// here when no file args
|
|
|
|
}
|
|
|
|
for (int i = optind; i < argc; ++i) {
|
|
|
|
try {
|
|
|
|
// process file argv[i]
|
|
|
|
} catch (const std::runtime_error& ex) {
|
|
|
|
std::cerr << "curly: " << ex.what() << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << "hello, curly\n";
|
2020-09-02 09:53:22 +02:00
|
|
|
requester req;
|
|
|
|
std::cout << req.get("https://www.swiftcoder.nl/") << '\n';
|
|
|
|
std::cout << req.get("https://www.swiftcoder.nl/moneydance/") << '\n';
|
2020-09-01 16:12:41 +02:00
|
|
|
|
|
|
|
} catch (const std::exception& ex) {
|
|
|
|
std::cerr << "curly: " << ex.what() << '\n';
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|