forked from docopt/docopt.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_testcase.cpp
40 lines (32 loc) · 751 Bytes
/
run_testcase.cpp
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
//
// docopt_tests.cpp
// docopt
//
// Created by Jared Grubb on 2013-11-03.
// Copyright (c) 2013 Jared Grubb. All rights reserved.
//
#include "docopt.h"
#include <iostream>
int main(int argc, const char** argv)
{
if (argc < 2) {
std::cerr << "Usage: docopt_tests USAGE [arg]..." << std::endl;
exit(-5);
}
std::string usage = argv[1];
std::vector<std::string> args {argv+2, argv+argc};
auto result = docopt::docopt(usage, args);
// print it out in JSON form
std::cout << "{ ";
bool first = true;
for(auto const& arg : result) {
if (first) {
first = false;
} else {
std::cout << "," << std::endl;
}
std::cout << '"' << arg.first << '"' << ": " << arg.second;
}
std::cout << " }" << std::endl;
return 0;
}