quick.cpp 1.0 KB

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