AOSharedServiceLibrary
|
The CommandLineInterpreter makes working with input parameters easier. With it, we get access to command line arguments that are entered in the form:
./example name=abc
We start by importing the necessary interfaces and establish the service factory.
#include "aossl/commandline/include/factory_cli.h" #include "aossl/core/include/kv_store_interface.h" int main( int argc, char** argv ) { AOSSL::CommandLineInterpreterFactory cli_factory; AOSSL::KeyValueStoreInterface *cli = cli_factory.get_command_line_interface( argc, argv );
We have access to an opt_exist method to determine if an option was entered, and we can use get_opt to pull parameter values.
if ( cli->opt_exist("name") ) { AOSSL::StringBuffer buf; cli->get_opt("name", buf); std::cout << buf.val << std::endl; } return 0; }
The Command Line Interpreter is threadsafe, and it is recommended that you utilize a single interpreter and have each thread access the arguments in it, to ensure that the input parameters are only parsed once.