| 1 | |
|---|---|
| 2 | // Copyright 2017 Peter Dimov. |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0. |
| 5 | // |
| 6 | // See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt |
| 8 | |
| 9 | // See library home page at http://www.boost.org/libs/program_options |
| 10 | |
| 11 | #include <boost/program_options.hpp> |
| 12 | #include <boost/core/lightweight_test.hpp> |
| 13 | |
| 14 | namespace po = boost::program_options; |
| 15 | |
| 16 | int main( int argc, char const* argv[] ) |
| 17 | { |
| 18 | po::options_description desc( "Allowed options"); |
| 19 | |
| 20 | desc.add_options() |
| 21 | ( "path,p", po::value<std::string>(), "set initial path") |
| 22 | ; |
| 23 | |
| 24 | po::variables_map vm; |
| 25 | |
| 26 | try |
| 27 | { |
| 28 | po::store( options: po::parse_command_line( argc, argv, desc ), m&: vm ); |
| 29 | po::notify( m&: vm ); |
| 30 | } |
| 31 | catch( std::exception const & x ) |
| 32 | { |
| 33 | std::cerr << "Error: "<< x.what() << std::endl; |
| 34 | return 1; |
| 35 | } |
| 36 | |
| 37 | std::string p; |
| 38 | |
| 39 | if( vm.count( x: "path") ) |
| 40 | { |
| 41 | p = vm[ "path"].as<std::string>(); |
| 42 | } |
| 43 | |
| 44 | std::string expected( "initial"); |
| 45 | |
| 46 | BOOST_TEST_EQ( p, expected ); |
| 47 | |
| 48 | return boost::report_errors(); |
| 49 | } |
| 50 |
