From 662fa9c7a299c70bf5e7ee4266fb3db258b7e979 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Sat, 1 Jul 2017 21:18:01 +0200 Subject: [PATCH] Added --output CLI option --- src/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ff05e59..a2825ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,6 +23,7 @@ #include #include #include "targetShapeSet.h" +#include using std::exception; using std::string; @@ -35,8 +36,10 @@ using std::make_shared; using std::map; using std::chrono::duration; using std::chrono::duration_cast; +using std::ofstream; using boost::filesystem::path; using boost::adaptors::transformed; +using boost::optional; namespace tclap = TCLAP; @@ -103,6 +106,7 @@ int main(int argc, char *argv[]) { tclap::CmdLine cmd(appName, argumentValueSeparator, appVersion); cmd.setExceptionHandling(false); cmd.setOutput(new NiceCmdLineOutput()); + tclap::ValueArg outputFileName("o", "output", "The output file path.", false, string(), "string", cmd); auto logLevels = vector(logging::LevelConverter::get().getValues()); tclap::ValuesConstraint logLevelConstraint(logLevels); tclap::ValueArg logLevel("", "logLevel", "The minimum log level to log", false, logging::Level::Debug, &logLevelConstraint, cmd); @@ -163,7 +167,12 @@ int main(int argc, char *argv[]) { // Export animation unique_ptr exporter = createExporter(exportFormat.getValue()); - exporter->exportAnimation(inputFilePath, animation, targetShapeSet, std::cout); + optional outputFile; + if (outputFileName.isSet()) { + outputFile = boost::in_place(outputFileName.getValue()); + outputFile->exceptions(std::ifstream::failbit | std::ifstream::badbit); + } + exporter->exportAnimation(inputFilePath, animation, targetShapeSet, outputFile ? *outputFile : std::cout); logging::info("Exiting application normally."); } catch (...) {