/*****************************************************************************/ // Copyright (c) Illumina 2008 // Author: Richard Shaw // // This software is covered by the "Illumina Genome Analyzer Software // License Agreement" and the "Illumina Source Code License Agreement", // and certain third party copyright/licenses, and any user of this // source file is bound by the terms therein (see accompanying files // Illumina_Genome_Analyzer_Software_License_Agreement.pdf and // Illumina_Source_Code_License_Agreement.pdf and third party // copyright/license notices). /*****************************************************************************/ #include #include #include #include "statistics/PQVS_Options.h" using namespace CommandLine; /*****************************************************************************/ PQVS_Options::PQVS_Options() : CommandLine::Options(), my_input_compr_name("none"), my_input_compr(File_Buffer::compressionNone) { ; } /*****************************************************************************/ PQVS_Options::~PQVS_Options() { ; } /*****************************************************************************/ int PQVS_Options::getOptions(int argc, char* const argv[]) throw (CommandLine::UnknownOptionException, CommandLine::MissingOptionException, CommandLine::InvalidArgumentException) { const char* short_option_cstr = "heaz:o:T:"; const struct option long_option_arr[] = { {"help", no_argument, 0, 'h'}, {"input_compr", required_argument, 0, 'z'}, {"output_file", required_argument, 0, 'o'}, {0, 0, 0, 0} }; int long_option_index(0); int option(0); // Note: case 'h' returns immediately. while (-1 != (option = getopt_long(argc, argv, short_option_cstr, long_option_arr, &long_option_index))) { switch (option) { case 0: break; case 'h': return usage(argc, argv); break; case 'z': my_input_compr_name = optarg; break; case 'o': my_output_path_str = optarg; break; case '?': case ':': default: throw UnknownOptionException(""); break; } } return RUN; } /*****************************************************************************/ void PQVS_Options::processOptions() throw (CommandLine::InvalidArgumentException) { std::string msg_str("input "); if (!resolve_compression(my_input_compr_name, my_input_compr, msg_str)) { throw InvalidArgumentException(msg_str); } } /*****************************************************************************/ void PQVS_Options::getParameters(int argc, char* const argv[]) throw (CommandLine::InvalidArgumentException) { // Expecting exactly 1 export input file if (argc <= optind) { throw InvalidArgumentException("No input file specified."); } my_input_path_str = argv[optind++]; const unsigned int num_unexpected_args(argc - optind); std::string msg_str(""); switch (num_unexpected_args) { case 0: return; case 1: msg_str = "Unexpected argument `"; break; default: msg_str = "Multiple unexpected arguments starting with `"; } msg_str += (std::string(argv[optind]) + "'.");; throw InvalidArgumentException(msg_str); } /*****************************************************************************/ int PQVS_Options::usage(int , char* const arg_cstr_arr[], const std::string& msg_str) { if (0 != msg_str.size()) { std::cerr << "ERROR: " << msg_str << std::endl; } const std::string app_name(arg_cstr_arr[0]); std::ostringstream ostrm; ostrm << "Usage : " << app_name << " -h|--help" << std::endl << " OR : " << app_name << std::endl << "[-z|--input_compr ]" << std::endl << "-o|--output_file " << std::endl << "" << std::endl; std::cerr << "INFO: " << ostrm.str() << std::endl; return NO_RUN; } /*****************************************************************************/