From 277be0d75619db5d3a747318a72d9f14e2e0850c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 5 Jan 2015 18:42:14 +0000 Subject: Use boost::program_options for cli --- slicer/tool/Jamfile.jam | 3 +++ slicer/tool/slicer.cpp | 30 +++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/slicer/tool/Jamfile.jam b/slicer/tool/Jamfile.jam index de50043..16942a0 100644 --- a/slicer/tool/Jamfile.jam +++ b/slicer/tool/Jamfile.jam @@ -1,5 +1,8 @@ +lib po : : boost_program_options ; + exe slicer : [ glob *.cpp ] : ../slicer//slicer + po ; diff --git a/slicer/tool/slicer.cpp b/slicer/tool/slicer.cpp index ce58c57..1a41bcb 100644 --- a/slicer/tool/slicer.cpp +++ b/slicer/tool/slicer.cpp @@ -1,17 +1,37 @@ #include +#include + +namespace po = boost::program_options; int main(int argc, char ** argv) { - if (argc < 3) { - fprintf(stderr, "slicer \n"); + boost::filesystem::path slice; + boost::filesystem::path cpp; + + po::options_description opts("Slicer options"); + opts.add_options() + ("help,h", "Show this help message") + ("slice,i", po::value(&slice), "Input ICE Slice file") + ("cpp,o", po::value(&cpp), "Output C++ file"); + + po::positional_options_description p; + p.add("slice", 1); + p.add("cpp", 1); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(opts).positional(p).run(), vm); + po::notify(vm); + + if (vm.count("help") || slice.empty() || cpp.empty()) { + std::cout << opts << std::endl; return 1; } - const boost::filesystem::path slice = argv[1]; - const boost::filesystem::path cpp = argv[2]; - Slicer::Slicer::Apply(slice, cpp); return 0; } + + + -- cgit v1.2.3