summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: c2208c6e3aa4bbac7b822d0012a13b6c61a7ee28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include "docopt.h"

#include "interface_reader.hpp"

static const char USAGE[] =
R"(Usage: getif [INTERFACE ...]

-h --help     Show this help text.
--version     Show version.
)";

std::vector<std::string>
get_interface_names(std::map<std::string, docopt::value>& args)
{
    auto it = args.find("INTERFACE");
    if (it != args.end()) {
        if (it->second.isStringList()) {
            return it->second.asStringList();
        } else {
            std::cerr << "Argument parsing error." << std::endl;
            exit(1); // exit is okay, because this is main.cpp
        }
    } else {
        return {};
    }
}

int main(int argc, const char** argv) {
    std::map<std::string, docopt::value> args
        = docopt::docopt(USAGE,
                         { argv + 1, argv + argc },
                         true,         // show help if requested
                         "getif 1.0"); // version string

    for(auto const& arg : args) {
        std::cout << arg.first <<  arg.second << std::endl;
    }

    return 0;
}