本文整理汇总了C++中OptionsParser::parse方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionsParser::parse方法的具体用法?C++ OptionsParser::parse怎么用?C++ OptionsParser::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OptionsParser
的用法示例。
在下文中一共展示了OptionsParser::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char** argv)
{
string inFile = "";
string tileDir = "/class/cs225/mp6_bmps/";
string numTilesStr = "100";
string pixelsPerTileStr = "50";
string outFile = "mosaic.png";
OptionsParser optsparse;
optsparse.addArg(inFile);
optsparse.addArg(tileDir);
optsparse.addArg(numTilesStr);
optsparse.addArg(pixelsPerTileStr);
optsparse.addArg(outFile);
optsparse.addOption("help", opts::help);
optsparse.addOption("h", opts::help);
optsparse.parse(argc, argv);
if (opts::help)
{
cout << "Usage: " << argv[0] << " background_image.png tile_directory/ [number of tiles] [pixels per tile] [output_image.png]" << endl;
return 0;
}
if (inFile == "")
{
cout << "Usage: " << argv[0] << " background_image.png tile_directory/ [number of tiles] [pixels per tile] [output_image.png]" << endl;
return 1;
}
makePhotoMosaic(inFile, tileDir, lexical_cast<int>(numTilesStr), lexical_cast<int>(pixelsPerTileStr), outFile);
return 0;
}
示例2: getTraversalKind
TraversalKind getTraversalKind (int argc, char* argv[])
{
const char* STR_TRAVERSAL_MODE = "-traversal";
TraversalKind result;
// We create a command line parser.
OptionsParser parser ("Traversal");
parser.push_back (new OptionOneParam (STR_TRAVERSAL_MODE, "traversal mode ('unitig' or 'contig'", true));
// We retrieve the traversal kind.
try
{
IProperties* props = parser.parse (argc, argv);
parse (props->getStr(STR_TRAVERSAL_MODE), result);
}
catch (OptionFailure& e)
{
e.displayErrors (std::cout);
exit (EXIT_FAILURE);
}
catch (Exception& e)
{
cout << e.getMessage() << endl;
exit (EXIT_FAILURE);
}
return result;
}
示例3: main
int main (int argc, char* argv[])
{
// We create a command line parser.
OptionsParser parser ("SortingCount");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "sorting count input", true));
try
{
// Shortcuts.
typedef Kmer<>::Count Count;
typedef Kmer<>::Type Type;
// We parse the user options.
IProperties* options = parser.parse (argc, argv);
// We load the object storing the couples [kmer,abundance]
Storage* storage = StorageFactory(STORAGE_HDF5).load (options->getStr(STR_URI_INPUT)); LOCAL (storage);
// We get the group inside the storage object
Group& dskGroup = storage->getGroup("dsk");
// We retrieve the partition holding the couples [kmer,abundance]
Partition<Count>& solidKmers = dskGroup.getPartition<Count> ("solid");
// Now, we read the couples in two ways, computing a checksum in each case.
Type checksum1, checksum2;
// CASE 1: we read the couples [kmer,abundance] with an iterator over the whole partition
Iterator<Count>* it = solidKmers.iterator(); LOCAL (it);
for (it->first(); !it->isDone(); it->next()) { checksum1 = checksum1 + it->item().value; }
// CASE 2: we read the couples [kmer,abundance] with an iterator over each collection of the partition
for (size_t i=0; i<solidKmers.size(); i++)
{
// We get the current collection inside the partition
Collection<Count>& collection = solidKmers [i];
Iterator<Count>* it = collection.iterator(); LOCAL (it);
for (it->first(); !it->isDone(); it->next()) { checksum2 = checksum2 + it->item().value; }
}
// We check that we got the same checksum
cout << "checksum1=" << checksum1 << endl;
cout << "checksum2=" << checksum1 << endl;
}
catch (OptionFailure& e)
{
return e.displayErrors (std::cout);
}
catch (Exception& e)
{
std::cerr << "EXCEPTION: " << e.getMessage() << std::endl;
}
return EXIT_SUCCESS;
}
示例4: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankFilter");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank reference", true));
parser.push_back (new OptionOneParam (STR_URI_SEQ_IDS, "file holding indexes of bank", true));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
/** We read the list of indexes. */
set<size_t> indexes;
FILE* file = fopen (options->getStr(STR_URI_SEQ_IDS).c_str(), "r");
if (file != 0)
{
char buffer[128];
while (fgets (buffer, sizeof(buffer), file)) { indexes.insert (atoi(buffer)); }
fclose (file);
}
cout << "found " << indexes.size() << " indexes" << endl;
/** We open the output bank. */
string outputBankUri = options->getStr(STR_URI_INPUT) + "_" + System::file().getBaseName (options->getStr(STR_URI_SEQ_IDS));
IBank* outputBank = Bank::open (outputBankUri);
LOCAL (outputBank);
/** We loop the input bank. */
IBank* inputBank = Bank::open (options->getStr(STR_URI_INPUT));
LOCAL (inputBank);
/** We use another iterator for filtering out some sequences. */
FilterIterator<Sequence,FilterFunctor> itSeq (inputBank->iterator(), FilterFunctor(indexes));
/** We loop the sequences. */
for (itSeq.first(); !itSeq.isDone(); itSeq.next())
{
outputBank->insert (itSeq.item());
}
/** We flush the output bank. */
outputBank->flush();
}
catch (OptionFailure& e)
{
return e.displayErrors (cout);
}
catch (Exception& e)
{
cerr << "EXCEPTION: " << e.getMessage() << endl;
}
}
示例5: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankFilter");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank input", true));
parser.push_back (new OptionOneParam (STR_FILTER_RATIO, "skip a sequence if 'good letters number / seq.len > X'", false, "0.8"));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
/** Shortcuts. */
double percentThreshold = options->getDouble(STR_FILTER_RATIO);
/** We open the input bank. */
IBank* inBank = Bank::open (options->getStr(STR_URI_INPUT));
LOCAL (inBank);
/** We create the output inBank. */
IBank* outBank = new BankFasta (options->getStr(STR_URI_INPUT) + "_filtered");
LOCAL (outBank);
/** We iterate the inBank. NOTE: WE USE A LAMBDA EXPRESSION HERE. */
inBank->iterate ([&] (Sequence& s)
{
/** Shortcut. */
char* data = s.getDataBuffer();
size_t nbOK = 0;
for (size_t i=0; i<s.getDataSize(); i++)
{
if (data[i]=='A' || data[i]=='C' || data[i]=='G' || data[i]=='T') { nbOK++; }
}
if ((double)nbOK / (double)s.getDataSize() > percentThreshold) { outBank->insert (s); }
});
/** We flush the output bank. */
outBank->flush();
}
catch (OptionFailure& e)
{
return e.displayErrors (cout);
}
catch (Exception& e)
{
cerr << "EXCEPTION: " << e.getMessage() << endl;
}
}
示例6: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("bankgen");
const char* OUTPUT_PREFIX = "-out";
const char* SEQ_LEN = "-seq-len";
const char* READ_LEN = "-read-len";
const char* OVERLAP_LEN = "-overlap-len";
const char* COVERAGE = "-coverage";
parser.push_back (new OptionOneParam (OUTPUT_PREFIX, "output prefix", true));
parser.push_back (new OptionOneParam (SEQ_LEN, "sequence length", false, "1000000"));
parser.push_back (new OptionOneParam (READ_LEN, "read length", false, "150" ));
parser.push_back (new OptionOneParam (OVERLAP_LEN, "overlap between two reads", false, "50" ));
parser.push_back (new OptionOneParam (COVERAGE, "coverage", false, "3" ));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
/** We create the random sequence. */
IBank* randomBank = new BankRandom (1, options->getInt(SEQ_LEN));
LOCAL (randomBank);
/** We create the reads bank. */
IBank* readsBank = new BankSplitter (
randomBank,
options->getInt(READ_LEN),
options->getInt(OVERLAP_LEN),
options->getInt(COVERAGE)
);
LOCAL (readsBank);
/** We save the random bank. */
SaveAsFasta (randomBank, options->getStr(OUTPUT_PREFIX) + "_sequence.fa");
/** We save the reads bank. */
SaveAsFasta (readsBank, options->getStr(OUTPUT_PREFIX) + "_reads.fa");
}
catch (OptionFailure& e)
{
e.getParser().displayErrors (stdout);
e.getParser().displayHelp (stdout);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
示例7: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankStats");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank input", true));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
std::string filename = options->getStr(STR_URI_INPUT);
//! [snippet16_bank]
// We get an instance of IBank from the URI.
IBank* bank = Bank::open (filename);
//! [snippet16_seq]
// We create an iterator on the bank
Iterator<Sequence>* it = bank->iterator();
// We iterate the sequences of the bank
for (it->first(); !it->isDone(); it->next())
{
// We get a shortcut on the current sequence and its data
Sequence& seq = it->item();
Data& data = seq.getData();
// We dump some information about the sequence.
std::cout << "comment " << seq.getComment() << std::endl;
// We dump each nucleotide. NOTE: the output depends on the data encoding
for (size_t i=0; i<data.size(); i++) { std::cout << data[i]; } std::cout << std::endl;
}
//! [snippet16_seq]
// The bank and the iterator have been allocated on the heap, so we have to delete them
delete it;
delete bank;
//! [snippet16_bank]
}
catch (OptionFailure& e)
{
return e.displayErrors (std::cout);
}
catch (Exception& e)
{
std::cerr << "EXCEPTION: " << e.getMessage() << std::endl;
}
}
示例8: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankStats");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank input", true));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
// We get information about the bank.
u_int64_t nbSequences=0, dataSize=0, seqMaxSize=0, seqMinSize=~0;
// We declare an input Bank and use it locally
IBank* inputBank = Bank::open (options->getStr(STR_URI_INPUT));
LOCAL (inputBank);
ProgressIterator<Sequence> it (*inputBank, "iterate");
for (it.first(); !it.isDone(); it.next())
{
Data& data = it.item().getData();
nbSequences ++;
if (data.size() > seqMaxSize) { seqMaxSize = data.size(); }
if (data.size() < seqMinSize) { seqMinSize = data.size(); }
dataSize += data.size ();
}
std::cout << "data size : " << dataSize << std::endl;
std::cout << "sequence number : " << nbSequences << std::endl;
std::cout << "sequence max size : " << seqMaxSize << std::endl;
std::cout << "sequence min size : " << seqMinSize << std::endl;
}
catch (OptionFailure& e)
{
return e.displayErrors (std::cout);
}
catch (Exception& e)
{
std::cerr << "EXCEPTION: " << e.getMessage() << std::endl;
}
}
示例9: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankDump");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank input", true));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
/** We dump the bank hierarchy. */
dump (Bank::open (options->getStr(STR_URI_INPUT)));
}
catch (OptionFailure& e)
{
return e.displayErrors (std::cout);
}
catch (Exception& e)
{
std::cerr << "EXCEPTION: " << e.getMessage() << std::endl;
}
}
示例10: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("GraphStats");
parser.push_back (new OptionOneParam (STR_URI_GRAPH, "graph input", true));
parser.push_back (new OptionOneParam (STR_NB_CORES, "nb cores", false, "0"));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
// We load the graph
Graph graph = Graph::load (options->getStr(STR_URI_GRAPH));
// We set the number of cores to be used. Use all available cores if set to 0.
size_t nbCores = options->getInt(STR_NB_CORES);
// We get an iterator for branching nodes of the graph.
// We use a progress iterator to get some progress feedback
ProgressGraphIterator<BranchingNode,ProgressTimer> itBranching (graph.iterator<BranchingNode>(), "statistics");
// We define some kind of unique identifier for a couple (indegree,outdegree)
typedef pair<size_t,size_t> InOut_t;
// We want to gather some statistics during the iteration.
// Note the use of ThreadObject: this object will be cloned N times (one object per thread) and each clone will
// be reachable within the iteration block through ThreadObject::operator()
ThreadObject <map <InOut_t, size_t> > topology;
// We dispatch the iteration on several cores. Note the usage of lambda expression here.
IDispatcher::Status status = Dispatcher(nbCores).iterate (itBranching, [&] (const BranchingNode& node)
{
// We retrieve the current instance of map <InOut_t,size_t> for the current running thread.
map <InOut_t,size_t>& localTopology = topology();
// We get branching nodes neighbors for the current branching node.
Graph::Vector<BranchingEdge> successors = graph.successors <BranchingEdge> (node);
Graph::Vector<BranchingEdge> predecessors = graph.predecessors<BranchingEdge> (node);
// We increase the occurrences number for the current couple (in/out) neighbors
localTopology [make_pair(predecessors.size(), successors.size())] ++;
});
// Now, the parallel processing is done. We want now to aggregate the information retrieved
// in each thread in a single map.
// We get each map<InOut_t,size_t> object filled in each thread, and we add its data into the "global" map.
// The global map is reachable through the ThreadObject::operator*. The "topology.foreach" will loop over
// all cloned object used in the threads.
topology.foreach ([&] (const map <InOut_t, size_t>& t)
{
// We update the occurrence of the current couple (in/out)
for_each (t.begin(), t.end(), [&] (const pair<InOut_t, size_t>& p) { (*topology)[p.first] += p.second; });
});
// We sort the statistics by decreasing occurrence numbers. Since map have its own ordering, we need to put all
// the data into a vector and sort it with our own sorting criteria.
vector < pair<InOut_t,size_t> > stats;
for (auto it = topology->begin(); it != topology->end(); it++) { stats.push_back (*it); }
sort (stats.begin(), stats.end(), [=] (const pair<InOut_t,size_t>& a, const pair<InOut_t,size_t>& b) { return a.second > b.second; });
printf ("\nThere are %d branching nodes with the following distribution: \n", itBranching.size());
size_t sum=0;
for (size_t i=0; i<stats.size(); i++)
{
sum += stats[i].second;
printf (" [in=%d out=%d] nb=%7d percent=%5.2f distrib=%5.2f\n",
stats[i].first.first,
stats[i].first.second,
stats[i].second,
100.0*(float)stats[i].second / (float)itBranching.size(),
100.0*(float)sum / (float)itBranching.size()
);
}
printf ("\nDone on %d cores in %.2f sec\n\n", status.nbCores, (float)status.time/1000.0);
}
catch (OptionFailure& e)
{
return e.displayErrors (std::cout);
}
catch (Exception& e)
{
std::cerr << "EXCEPTION: " << e.getMessage() << std::endl;
}
return EXIT_SUCCESS;
}
示例11: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("KmerTest");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank input", true));
parser.push_back (new OptionOneParam (STR_KMER_SIZE, "kmer size", true));
parser.push_back (new OptionOneParam (STR_MINIMIZER_SIZE, "minimizer size", true));
parser.push_back (new OptionNoParam (STR_VERBOSE, "display kmers", false));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
// We get the kmer and minimizer sizes.
size_t kmerSize = options->getInt(STR_KMER_SIZE);
size_t mmerSize = options->getInt(STR_MINIMIZER_SIZE);
// We define a try/catch block in case some method fails (bad filename for instance)
u_int64_t nbKmers = 0;
bool display = options->get(STR_VERBOSE) != 0;
// We declare a Bank instance defined by a list of filenames
IBank* bank = Bank::open (options->getStr(STR_URI_INPUT));
LOCAL (bank);
// We declare a kmer model and a minimizer model
Model model (kmerSize, mmerSize);
// We get a reference on the minimizer model, which will be useful for dumping
const ModelMinimizer::Model& modelMinimizer = model.getMmersModel();
Kmer<span>::Type checksum;
size_t nbChanged = 0;
size_t nbInvalid = 0;
// We define an iterator that encapsulates the sequences iterator with progress feedback
ProgressIterator<Sequence> iter (*bank, "iterate bank");
// We loop over sequences.
for (iter.first(); !iter.isDone(); iter.next())
{
// Shortcut
Sequence& seq = iter.item();
//! [snippet1_iterate]
// We iterate the kmers (and minimizers) of the current sequence.
model.iterate (seq.getData(), [&] (const Model::Kmer& kmer, size_t idx)
{
nbKmers ++;
if (kmer.hasChanged() == true) { nbChanged++; }
if (kmer.isValid() == false) { nbInvalid++; }
checksum += kmer.minimizer().value();
});
//! [snippet1_iterate]
}
cout << "nbKmers : " << nbKmers << endl;
cout << "nbInvalid : " << nbInvalid << endl;
cout << "nbChanged : " << nbChanged << endl;
cout << "ratio : " << (nbChanged > 0 ? (double)nbKmers / (double)nbChanged : 0) << endl;
cout << "checksum : " << checksum << endl;
}
catch (OptionFailure& e)
{
return e.displayErrors (std::cout);
}
catch (Exception& e)
{
std::cerr << "EXCEPTION: " << e.getMessage() << std::endl;
}
return EXIT_SUCCESS;
}
示例12: if
int
SwitchWContexts::init_from_command_line_options(int argc, char *argv[],
TargetParserIface *tp) {
OptionsParser parser;
parser.parse(argc, argv, tp);
notifications_addr = parser.notifications_addr;
auto transport = std::shared_ptr<TransportIface>(
TransportIface::make_nanomsg(notifications_addr));
transport->open();
#ifdef BMDEBUG_ON
// has to be before init_objects because forces arith
if (parser.debugger) {
for (Context &c : contexts)
c.set_force_arith(true);
Debugger::init_debugger(parser.debugger_addr);
}
#endif
event_logger_addr = parser.event_logger_addr;
if (parser.console_logging)
Logger::set_logger_console();
if (parser.file_logger != "")
Logger::set_logger_file(parser.file_logger, parser.log_flush);
Logger::set_log_level(parser.log_level);
int status = init_objects(parser.config_file_path, parser.device_id,
transport);
if (status != 0) return status;
if (parser.use_files)
set_dev_mgr_files(parser.wait_time);
else if (parser.packet_in)
set_dev_mgr_packet_in(device_id, parser.packet_in_addr, transport);
else
set_dev_mgr_bmi(device_id, transport);
for (const auto &iface : parser.ifaces) {
std::cout << "Adding interface " << iface.second
<< " as port " << iface.first
<< (parser.use_files ? " (files)" : "")
<< std::endl;
const char* inFileName = NULL;
const char* outFileName = NULL;
std::string inFile;
std::string outFile;
if (parser.use_files) {
inFile = iface.second + "_in.pcap";
inFileName = inFile.c_str();
outFile = iface.second + "_out.pcap";
outFileName = outFile.c_str();
} else if (parser.pcap) {
inFile = iface.second + ".pcap";
inFileName = inFile.c_str();
outFileName = inFileName;
}
port_add(iface.second, iface.first, inFileName, outFileName);
}
thrift_port = parser.thrift_port;
if (parser.state_file_path != "") {
status = deserialize_from_file(parser.state_file_path);
if (status != 0) return status;
}
// TODO(unknown): is this the right place to do this?
set_packet_handler(packet_handler, static_cast<void *>(this));
start();
return status;
}
示例13: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankSplitter");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank reference", true));
parser.push_back (new OptionOneParam (STR_MAX_INPUT_SIZE, "average db size per split", true));
parser.push_back (new OptionOneParam (STR_URI_OUTPUT_DIR, "output directory", false, "."));
parser.push_back (new OptionNoParam (STR_OUTPUT_FASTQ, "fastq output", false));
parser.push_back (new OptionNoParam (STR_OUTPUT_GZ, "gzip output", false));
// We define a try/catch block in case some method fails (bad filename for instance)
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
/** Shortcuts. */
u_int64_t maxDbSize = options->getInt(STR_MAX_INPUT_SIZE);
// We declare an input Bank
IBank* inputBank = Bank::open (options->getStr(STR_URI_INPUT));
LOCAL (inputBank);
// We get the basename of the input bank.
string inputBasename = System::file().getBaseName (options->getStr(STR_URI_INPUT));
/** We set the name of the output directory. */
stringstream ss; ss << inputBasename << "_S" << maxDbSize;
string outputDirName = ss.str();
/** We create the output directory. */
string outputDir = options->getStr(STR_URI_OUTPUT_DIR) + "/" + outputDirName;
System::file().mkdir (outputDir, S_IRWXU);
// We create the album bank.
BankAlbum album (outputDir + "/album.txt");
/** We get estimations about the bank. */
u_int64_t number, totalSize, maxSize;
inputBank->estimate (number, totalSize, maxSize);
u_int64_t estimationNbSeqToIterate = number;
// We create an iterator over the input bank
ProgressIterator<Sequence> itSeq (*inputBank, "split");
// We loop over sequences to get the exact number of sequences.
int64_t nbBanksOutput = -1;
u_int64_t nbSequences = 0;
u_int64_t dbSize = ~0;
bool isFastq = options->get(STR_OUTPUT_FASTQ) != 0;
bool isGzipped = options->get(STR_OUTPUT_GZ) != 0;
IBank* currentBank = 0;
for (itSeq.first(); !itSeq.isDone(); itSeq.next())
{
if (dbSize > maxDbSize)
{
if (currentBank != 0) { currentBank->flush(); currentBank->finalize(); }
nbBanksOutput ++;
/** We build the uri of the current bank. */
stringstream ss; ss << inputBasename << "_" << nbBanksOutput << (isFastq ? ".fastq" : ".fasta");
if (isGzipped) { ss << ".gz"; }
/** We create a new bank and put it in the album. */
currentBank = album.addBank (outputDir, ss.str(), isFastq, isGzipped);
/** We reinit the db size counter. */
dbSize = 0;
}
dbSize += itSeq->getDataSize();
/** We insert the sequence into the current output bank. */
currentBank->insert (*itSeq);
}
if (currentBank != 0) { currentBank->flush(); }
}
catch (OptionFailure& e)
{
return e.displayErrors (cout);
}
catch (Exception& e)
{
cerr << "EXCEPTION: " << e.getMessage() << endl;
}
}
示例14: processArgs
void monad::processArgs(int argc, const char* const* argv)
{
// Create OptionsMap for options and vector for positional arguments:
OptionsParser options;
// Add our possible options to our map
options.addOption("solution", opts::solution);
options.addOption("newtests", opts::newtests);
options.addOption("provided", opts::provided);
options.addOption("clean", opts::clean);
options.addOption("update", opts::update);
options.addOption("staff", opts::staff);
options.addOption("optimize", opts::optimize);
options.addOption("detailed", opts::detailed);
options.addOption("verbose", opts::verbose);
options.addOption("buffer", opts::buffer);
options.addOption("asan", opts::asan);
options.addOption("parallel", opts::parallel);
options.addOption("help", opts::help);
options.addOption("h", opts::help);
options.addOption("info", opts::info);
options.addOption("version", opts::info);
options.addOption("v", opts::info);
options.addOption("license", opts::license);
// Add arguments
string assignment = "";
options.addArg(assignment);
// Read in options and arguments
vector<string> posargs = options.parse(argc, argv);
// Help
if (opts::help || toLower(assignment) == "help")
{
if (toLower(assignment) == "config")
printHelpConfig();
else if (toLower(assignment) == "tests")
printHelpTests();
else
printHelp();
exit(0);
}
// Info
if (opts::info)
{
printInfo();
exit(0);
}
// License
if (opts::license)
{
printLicense();
exit(0);
}
// Clean
if (toLower(assignment) == "clean")
{
system("/bin/rm -rf *_grade/ *_tests/ *_newtests/ *_provided/ "
"*_solution/");
exit(0);
}
// Check argument list length
if (assignment == "")
{
cout << "Usage: " << argv[0] << " mp1" << endl;
cout << "Run \'" << argv[0] << " --help\' for more information" << endl;
exit(0);
}
// Find mp/lab name and tests folder
if (assignment[assignment.length() - 1] == '/')
assignment = assignment.substr(0, assignment.length() - 1);
size_t slash_i = assignment.find_last_of('/');
string assignment_name =
(slash_i == string::npos) ? assignment : assignment.substr(slash_i + 1);
string assignment_dir =
(slash_i == string::npos) ? "" : assignment.substr(0, slash_i);
// TODO (toole1): All this stuff is ugly!
vector<string> splitname = tokenize(assignment_name, '.');
assignment_base = splitname[0];
if (splitname.size() == 1)
mp_part = no_mp_part;
else
mp_part = lexical_cast<int>(splitname[1].c_str());
gradeFolder = "./" + assignment_base + "_grade/";
if (!exists(gradeFolder))
opts::clean = true;
if (opts::clean)
tempFolder = "";
else
//.........这里部分代码省略.........
示例15: processArgs
void monad::processArgs(int argc, const char * const * argv)
{
// Create OptionsMap for options and vector for positional arguments:
OptionsParser options;
// Add our possible options to our map
options.addOption("solution", opts::solution);
options.addOption("newtests", opts::newtests);
options.addOption("provided", opts::provided);
options.addOption("clean", opts::clean);
options.addOption("update", opts::update);
options.addOption("staff", opts::staff);
options.addOption("optimize", opts::optimize);
options.addOption("verbose", opts::verbose);
options.addOption("buffer", opts::buffer);
options.addOption("valgrind", opts::valgrind);
options.addOption("parallel", opts::parallel);
options.addOption("help", opts::help);
options.addOption("h", opts::help);
options.addOption("info", opts::info);
options.addOption("version", opts::info);
options.addOption("v", opts::info);
options.addOption("license", opts::license);
// Add arguments
string assignment = "";
options.addArg(assignment);
// Read in options and arguments
vector<string> posargs = options.parse(argc, argv);
// Help
if (opts::help || toLower(assignment) == "help")
{
if (toLower(assignment) == "config")
printHelpConfig();
else if (toLower(assignment) == "tests")
printHelpTests();
else
printHelp();
exit(0);
}
// Info
if (opts::info)
{
printInfo();
exit(0);
}
// License
if (opts::license)
{
printLicense();
exit(0);
}
// Clean
if (toLower(assignment) == "clean")
{
system("/bin/rm -rf *_grade/ *_tests/ *_newtests/ *_providedtests *_solution/");
exit(0);
}
// Check argument list length
if (assignment == "")
{
cout << "Usage: " << argv[0] << " mp1" << endl;
cout << "Run \'" << argv[0] << " --help\' for more information" << endl;
exit(0);
}
// Find mp/lab name and tests folder
vector<string> splitname = tokenize(assignment, '.');
assignment_base = splitname[0];
if (splitname.size() == 1)
mp_part = no_mp_part;
else
mp_part = lexical_cast<int>(splitname[1].c_str());
gradeFolder = "./" + assignment_base + "_grade/";
if (!exists(gradeFolder)) opts::clean = true;
if (opts::clean)
tempFolder = "";
else
tempFolder = "./" + assignment_base + "_temp/";
// Find source folder (i.e. ../mp1)
if (opts::solution)
sourceFolder = updateFolder(assignment_base + "_solution/", false);
else
sourceFolder = getFolder(assignment_base + '/', false);
// tests folder
if (opts::provided)
testsFolder = updateFolder(assignment_base + "_provided/", false);
else if (opts::newtests)
//.........这里部分代码省略.........