options/main.cpp

39 lines
810 B
C++
Raw Permalink Normal View History

2019-08-08 17:54:29 +00:00
#include "options.hpp"
#include <iostream>
template<typename Iterator>
void print_list(std::ostream& out, Iterator start, Iterator end)
2019-08-08 17:54:29 +00:00
{
if (start == end)
{
out << "<empty>";
return;
}
2019-08-08 17:54:29 +00:00
for (; start != end; ++start)
2019-08-08 17:54:29 +00:00
{
out << '"' << *start << '"';
2019-08-08 17:54:29 +00:00
if (std::next(start) != end)
2019-08-08 17:54:29 +00:00
{
out << ", ";
2019-08-08 17:54:29 +00:00
}
}
}
2019-08-08 17:54:29 +00:00
int main(int argc, char** argv)
{
auto [opts, operands] = options::parse(argv + 1, argv + argc);
std::cerr << "Operands: ";
print_list(std::cerr, std::cbegin(operands), std::cend(operands));
std::cerr << '\n';
2019-08-08 17:54:29 +00:00
for (const auto& [name, args] : opts)
{
std::cerr << "" << name << "”: ";
print_list(std::cerr, std::cbegin(args), std::cend(args));
2019-08-08 17:54:29 +00:00
std::cerr << '\n';
}
}