/*
 *
 *
 *   opttest.cc
 *
 *
 */

#include <iostream>
#include <string>
#include "cmdline.h"

using namespace std;

int main (int argc, char **argv) {
	my::command_line::config cfg;

	cfg.add("-a", my::command_line::arg_none);
	cfg.add("-b", my::command_line::arg_none);
	cfg.add("-c", my::command_line::arg_optional);
	cfg.add("-d", my::command_line::arg_required);
	cfg.add("--long1", my::command_line::arg_none);
	cfg.add("--long2", my::command_line::arg_none);
	cfg.add("--long3", my::command_line::arg_optional);
	cfg.add("--long4", my::command_line::arg_required);

	my::command_line::parser args(cfg);

	try {
		args.parse(argc, argv);
	} catch (const std::exception &e) {
		cerr << "Error: " << e.what() << endl;
		return 1;
	}

	my::command_line::parser::option_container::iterator i;
	my::command_line::parser::option_container all_opts;
	my::command_line::parser::nonoption_container::iterator j;
	my::command_line::parser::nonoption_container all_nonopts;

	args.get_options(all_opts);
	args.get_nonoptions(all_nonopts);

	cout << "Total options parsed: " << (all_opts.size()) << endl;

	for (i = all_opts.begin(); i != all_opts.end(); ++i) {
		cout << "Option:" << endl;
		cout << "   + Name:   \'" << (i->name()) << '\'' << endl;
		cout << "   + Value:  \'" << (i->value()) << '\'' << endl;
		cout << "   + Count:   " << (i->count()) << endl;
	}

	cout << endl << "Total nonoption arguments parsed: "
		 << (all_nonopts.size()) << endl;

	for (j = all_nonopts.begin(); j != all_nonopts.end(); ++j) {
		cout << "Nonoption: " << *j << endl;
	}

	cout << "is_set: A, B, C, D = "
		 << args.is_set("-a") << ", "
		 << args.is_set("-b") << ", "
		 << args.is_set("-c") << ", "
		 << args.is_set("-d") << endl;

	return 0;
}
