From 6a838eeffbc6ed30b1e5509b64ff50b69db8b75a Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Mon, 18 Dec 2017 12:42:12 +0200 Subject: [build] Replace boost_libprogram_options with args --- bin/offline.cpp | 76 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 33 deletions(-) (limited to 'bin/offline.cpp') diff --git a/bin/offline.cpp b/bin/offline.cpp index ec2fb09096..5b403a6416 100644 --- a/bin/offline.cpp +++ b/bin/offline.cpp @@ -4,53 +4,63 @@ #include +#include + #include #include #include #include +#include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunknown-pragmas" -#pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#pragma GCC diagnostic ignored "-Wshadow" -#include -#pragma GCC diagnostic pop - -namespace po = boost::program_options; using namespace std::literals::chrono_literals; int main(int argc, char *argv[]) { - std::string style = mbgl::util::default_styles::streets.url; - double north = 37.2, west = -122.8, south = 38.1, east = -121.7; // Bay area - double minZoom = 0.0, maxZoom = 15.0, pixelRatio = 1.0; - std::string output = "offline.db"; + args::ArgumentParser argumentParser("Mapbox GL offline tool"); + args::HelpFlag helpFlag(argumentParser, "help", "Display this help menu", {'h', "help"}); - const char* tokenEnv = getenv("MAPBOX_ACCESS_TOKEN"); - std::string token = tokenEnv ? tokenEnv : std::string(); - - po::options_description desc("Allowed options"); - desc.add_options() - ("style,s", po::value(&style)->value_name("URL"), "Map stylesheet") - ("north", po::value(&north)->value_name("degrees")->default_value(north), "North latitude") - ("west", po::value(&west)->value_name("degrees")->default_value(west), "West longitude") - ("south", po::value(&south)->value_name("degrees")->default_value(south), "South latitude") - ("east", po::value(&east)->value_name("degrees")->default_value(east), "East longitude") - ("minZoom", po::value(&minZoom)->value_name("number")->default_value(minZoom), "Min zoom level") - ("maxZoom", po::value(&maxZoom)->value_name("number")->default_value(maxZoom), "Max zoom level") - ("pixelRatio", po::value(&pixelRatio)->value_name("number")->default_value(pixelRatio), "Pixel ratio") - ("token,t", po::value(&token)->value_name("key")->default_value(token), "Mapbox access token") - ("output,o", po::value(&output)->value_name("file")->default_value(output), "Output database file name") - ; + args::ValueFlag tokenValue(argumentParser, "key", "Mapbox access token", {'t', "token"}); + args::ValueFlag styleValue(argumentParser, "URL", "Map stylesheet", {'s', "style"}); + args::ValueFlag outputValue(argumentParser, "file", "Output database file name", {'o', "output"}); + + args::ValueFlag northValue(argumentParser, "degrees", "North latitude", {"north"}); + args::ValueFlag westValue(argumentParser, "degrees", "West longitude", {"west"}); + args::ValueFlag southValue(argumentParser, "degrees", "South latitude", {"south"}); + args::ValueFlag eastValue(argumentParser, "degrees", "East longitude", {"east"}); + args::ValueFlag minZoomValue(argumentParser, "number", "Min zoom level", {"minZoom"}); + args::ValueFlag maxZoomValue(argumentParser, "number", "Max zoom level", {"maxZoom"}); + args::ValueFlag pixelRatioValue(argumentParser, "number", "Pixel ratio", {"pixelRatio"}); try { - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - } catch(std::exception& e) { - std::cout << "Error: " << e.what() << std::endl << desc; + argumentParser.ParseCLI(argc, argv); + } catch (args::Help) { + std::cout << argumentParser; + exit(0); + } catch (args::ParseError e) { + std::cerr << e.what() << std::endl; + std::cerr << argumentParser; exit(1); + } catch (args::ValidationError e) { + std::cerr << e.what() << std::endl; + std::cerr << argumentParser; + exit(2); } + std::string style = styleValue ? args::get(styleValue) : mbgl::util::default_styles::streets.url; + + // Bay area + const double north = northValue ? args::get(northValue) : 37.2; + const double west = westValue ? args::get(westValue) : -122.8; + const double south = southValue ? args::get(southValue) : 38.1; + const double east = eastValue ? args::get(eastValue) : -121.7; + + const double minZoom = minZoomValue ? args::get(minZoomValue) : 0.0; + const double maxZoom = maxZoomValue ? args::get(maxZoomValue) : 15.0; + const double pixelRatio = pixelRatioValue ? args::get(pixelRatioValue) : 1.0; + const std::string output = outputValue ? args::get(outputValue) : "offline.db"; + + const char* tokenEnv = getenv("MAPBOX_ACCESS_TOKEN"); + const std::string token = tokenValue ? args::get(tokenValue) : (tokenEnv ? tokenEnv : std::string()); + using namespace mbgl; util::RunLoop loop; -- cgit v1.2.1