int main(int argc, const char * argv[]) { Clara::CommandLine<Config> cli; cli.bind( &Config::colour ) .describe( "specify a colour" ) .shortOpt( "c") .longOpt( "colour" ) .hint( "widget colour" ); Config cfg = cli.parseInto( argc, argv ); std::cout << "Hello, " << cfg.colour << " World!\n"; }
int integrationtest_main(int argc, char *argv[]) { IntegrationTestCLData configData; Clara::CommandLine<IntegrationTestCLData> cli; cli.bind( &IntegrationTestCLData::help ) .describe( "display usage information" ) .shortOpt( "?") .shortOpt( "h") .longOpt( "help" ); cli.bind( &IntegrationTestCLData::license ) .describe( "prints out the license of the tests" ) .shortOpt( "l") .longOpt( "license" ) .longOpt( "licence" ); cli.bind( &IntegrationTestCLData::seed ) .describe( "value to seed the randomizer" ) .shortOpt( "S") .longOpt( "seed" ) .hint("the_seed"); cli.bind( &IntegrationTestCLData::tmp ) .describe( "path to a temporary directory" ) .shortOpt( "t") .longOpt( "tmp" ) .hint( "path" ); cli.bind( &IntegrationTestCLData::wpkg ) .describe( "path to the wpkg executable" ) .shortOpt( "w") .longOpt( "wpkg" ) .hint( "path" ); cli.bind( &IntegrationTestCLData::version ) .describe( "print out the wpkg project version these integration tests pertain to" ) .shortOpt( "V") .longOpt( "version" ); cli.parseInto( argc, argv, configData ); if( configData.help ) { cli.usage( std::cout, argv[0] ); Catch::Session().run(argc, argv); exit(1); } if( configData.version ) { std::cout << debian_packages_version_string() << std::endl; exit(1); } if( configData.license ) { license::license(); exit(1); } std::vector<std::string> arg_list; for( int i = 0; i < argc; ++i ) { arg_list.push_back( argv[i] ); } // by default we get a different seed each time; that really helps // in detecting errors! (I know, I wrote loads of tests before) unsigned int seed(static_cast<unsigned int>(time(NULL))); if( configData.seed != 0 ) { seed = static_cast<unsigned int>(configData.seed); remove_from_args( arg_list, "--seed", "-s" ); } srand(seed); std::cout << "wpkg[" << getpid() << "]:integrationtest: seed is " << seed << std::endl; // we can only have one of those for ALL the tests that directly // access the library... // (because the result is cached and thus cannot change) #if defined(MO_WINDOWS) _putenv_s("WPKG_SUBST", "f=/opt/wpkg|/m2osw/packages:h=usr/local/bin/wpkg"); #else putenv(const_cast<char *>("WPKG_SUBST=f=/opt/wpkg|/m2osw/packages:h=usr/local/bin/wpkg")); #endif if( !configData.tmp.empty() ) { wpkg_tools::set_tmp_dir( configData.tmp ); remove_from_args( arg_list, "--tmp", "-t" ); } if( !configData.wpkg.empty() ) { wpkg_tools::set_wpkg_tool( configData.wpkg ); remove_from_args( arg_list, "--wpkg", "-w" ); } std::vector<char *> new_argv; for( const auto& arg : arg_list ) { new_argv.push_back( const_cast<char *>(arg.c_str()) ); } return Catch::Session().run( static_cast<int>(new_argv.size()), &new_argv[0] ); }
std::vector<Clara::Parser::Token> parseInto( Clara::CommandLine<ConfigT>& cli, char const * (&argv)[size], ConfigT& config ) { return cli.parseInto( size, argv, config ); }