From 865491d1012c5bc2291fb7463f483c2cd045c244 Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Fri, 7 Aug 2015 20:06:33 -0400 Subject: [PATCH] Added a help message to niftest Now using the boost argument parser. --- apps/niftest/niftest.cpp | 66 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/apps/niftest/niftest.cpp b/apps/niftest/niftest.cpp index 20c8597f3..fd060447c 100644 --- a/apps/niftest/niftest.cpp +++ b/apps/niftest/niftest.cpp @@ -2,12 +2,17 @@ #include #include +#include #include #include #include #include +#include + +// Create local aliases for brevity +namespace bpo = boost::program_options; ///See if the file has the named extension bool hasExtension(std::string filename, std::string extensionToFind) @@ -54,13 +59,68 @@ void readBSA(std::string filename) } } +std::vector parseOptions (int argc, char** argv) +{ + bpo::options_description desc("Ensure that OpenMW can use the provided NIF and BSA files\n\n" + "Usages:\n" + " niftool \n" + " Scan the file for read errors.\n\n" + "Allowed options"); + desc.add_options() + ("help,h", "print help message.") + ("input-file", bpo::value< std::vector >(), "input file") + ; + + //Default option if none provided + bpo::positional_options_description p; + p.add("input-file", -1); + + bpo::variables_map variables; + try + { + bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv). + options(desc).positional(p).run(); + bpo::store(valid_opts, variables); + } + catch(std::exception &e) + { + std::cout << "ERROR parsing arguments: " << e.what() << "\n\n" + << desc << std::endl; + exit(1); + } + + bpo::notify(variables); + if (variables.count ("help")) + { + std::cout << desc << std::endl; + exit(1); + } + if (variables.count("input-file")) + { + std::vector files = variables["input-file"].as< std::vector >(); + + std::cout << "Input files are:"; + for(std::vector::const_iterator it=files.begin(); it!=files.end(); ++it) + { + std::cout <<" "<< *it; + } + std::cout << std::endl; + return files; + } + + std::cout << "No input files or directories specified!" << std::endl; + std::cout << desc << std::endl; + exit(1); +} + int main(int argc, char **argv) { + std::vector files = parseOptions (argc, argv); std::cout << "Reading Files" << std::endl; - for(int i = 1; i::const_iterator it=files.begin(); it!=files.end(); ++it) + { + std::string name = *it; try{ if(isNIF(name))