/* _______ .__ .__ .__ .__ \ \ ____ __ __ _______ |__|| | | | |__| ____ ____ / | \ _/ __ \ | | \\_ __ \| || | | | | | / _ \ / \ / | \\ ___/ | | / | | \/| || |__| |__| |( <_> )| | \ \____|__ / \___ >|____/ |__| |__||____/|____/|__| \____/ |___| / =========\/======\/=================================================\/== v0.01 12/DEC/2007 Copyright 2007-2007 Scott D. Yelich SOME RIGHTS RESERVED ,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.-*~'`^`'~*-,._.,-*~'`^`'~*-, LICENSE: Creative Commons Attribution 3.0 License. SEE: http://creativecommons.org/licenses/by/3.0/ Wed Dec 12 21:44:19 EST 2007, v0.01 sdy This is a *very* simple program written to test command line processing. */ // PACKAGE #include "CommandLine.h" CommandLine commandLine; void usage() { std::cout << "Usage: " << commandLine.program() << " [options ...] [pagename]" << std::endl << "-h help (this information)" << std::endl << "-a option requiring no additional arguments" << std::endl << "-b x option requiring one additional argument" << std::endl << "-c x y option requiring two additional arguments" << std::endl << "-- ... stop processing command line options" << std::endl ; } int main(int argc, char *argv[]) { try { commandLine.process(argc, argv, "-a 0 -b 1 -c 2 -h 0"); } catch (TypedException & e) { switch (e.code()) { case CommandLine::InvalidFormat : std::cout << "Error: (InvalidFormat) " << e << " " << std::endl; exit(1); break; case CommandLine::RequiresParameter : std::cout << "Error: (RequiresParameter) " << e << " " << std::endl; exit(1); break; default : std::cout << "Unknown exception(" << e << ")" << std::endl; exit(1); break; } } if (commandLine.exists("-h")) { usage(); exit(0); } if (commandLine.exists("-a")) { std::cout << "Found: -a = \"" << commandLine.get("-a") << "\"" << std::endl; } if (commandLine.exists("-b")) { std::cout << "Found: -b = \"" << commandLine.get("-b") << "\"" << std::endl; } if (commandLine.exists("-c")) { std::cout << "Found: -c = \"" << commandLine.get("-c") << "\"" << std::endl; } if (commandLine.exists("--")) { std::cout << "Found: -- = \"" << commandLine.get("--") << "\"" << std::endl; } }