
Hi! Sorry for my English, I am from Russia. Is there any interest in a library which parse command line parameters and call correspond functions/functors? Features: - check type of parameter, - check "value semantic" of parameter, - set necessity of parameter, - maybe set default value for parameter, - some other settings. Example: void help() { std::cout << "This is my help info!" << std::endl; ::exit( 0 ); // Exit after printing help info. } struct config_file { void operator()( const std::string& file ) { // Some work with obtaining file path. } }; void limit( const std::string& some_limit_value ) { // int limit = boost::lexical_cast< int >( some_limit_value ); // ... } int main( int argc, char* argv[] ) { typedef command_line_parameter_parser clp_parser; clp_parser parser; parser.add_parameter( "-h", "--help", help ); // Short and full names, in Unix tradition. // In this case we define parameter with one name and value (it is must be valid path); // Without check_value() obtaining path will not be checked. parser.add_parameter( "--config", config_file, clp_parser::with_value ).check_value( clp_parser::path ); parser.add_parameter( "-l", "--limit", limit ).check_type( clp_parser::integer ); // Is integer? parser.set_value_separator( ':' ); // "--config:/home/file.conf" instead default "--config=/home/file.conf" try { parser.parse( argc, argv ); } catch ( const std::exception& exc ) { std::cerr << exc.what() << std::endl; } ... return 0; } Denis

Hi Denis,
Is there any interest in a library which parse command line parameters and call correspond functions/functors?
How does your library compare to Boost.Program_options [1]? -- Christoph [1] http://www.boost.org/doc/libs/1_42_0/doc/html/program_options.html

Christoph Heindl wrote:
Hi Denis
How does your library compare to Boost.Program_options [1]?
-- Christoph
[1] http://www.boost.org/doc/libs/1_42_0/doc/html/program_options.html
Hi, Christoph! I now about Boost.Program_options, and use it in my programs some time. But later I decide create my own solution, because Boost.Program_options have some limitation. First, it cannot call functions/functors. If I put in command line some parameter, I want some reaction on it. In my lib reaction occure immediately, in parsing process (but after all correction checks). Lib know nothing about this reaction's semantic, it just call correspond boost::signal. Second, it cannot check "value semantic" of parameters. If parameter's value must be a valid path (or valid IPv4, or some else), I may want to check it immediately, in parsing process. In this case, my lib checks value's validity (using Boost.Filesystem, or my own algorithms) and, if error occurs, generate correspond std::exception. Third (although it trifle), my lib allow set "name-value" separator. It can be useful, may be, I want use "--config:/home/my_file.conf" instead default "--config=/home/my_file.conf". Denis

Denis Shevchenko wrote:
Christoph Heindl wrote:
Hi Denis
How does your library compare to Boost.Program_options [1]?
-- Christoph
[1] http://www.boost.org/doc/libs/1_42_0/doc/html/program_options.html
Hi, Christoph!
I now about Boost.Program_options, and use it in my programs some time. But later I decide create my own solution, because Boost.Program_options have some limitation.
First, it cannot call functions/functors. If I put in command line some parameter, I want some reaction on it. In my lib reaction occure immediately, in parsing process (but after all correction checks). Lib know nothing about this reaction's semantic, it just call correspond boost::signal.
Oh? Surely there's typed_value::notifier that allows to specify callbacks.
Second, it cannot check "value semantic" of parameters. If parameter's value must be a valid path (or valid IPv4, or some else), I may want to check it immediately, in parsing process. In this case, my lib checks value's validity (using Boost.Filesystem, or my own algorithms) and, if error occurs, generate correspond std::exception.
It it unclear to me why you insist on doing such checks during the parsing. ProgramOptions performns such checking when parsed tokens are stored in variables_map, which seems like a sensible separation of responsibilities to me. - Volodya

Vladimir Prus wrote:
Oh? Surely there's typed_value::notifier that allows to specify callbacks. Sorry, I am not observe this possibility... It's my mistake... It it unclear to me why you insist on doing such checks during the parsing. ProgramOptions performns such checking when parsed tokens are stored in variables_map, which seems like a sensible separation of responsibilities to me.
- Volodya Performs such checking? Like path existing or correctness of IP-address? I cannot find it in your documentation. May be I badly read... Could you tell me, in which documentation's section I may read about this... Thank you.
Denis

Performs such checking? Like path existing or correctness of IP-address? I cannot find it in your documentation. May be I badly read... Could you tell me, in which documentation's section I may read about this... Thank you.
As far as I know, this feature is called a custom validator and you can read about it in the how-to section of the docs [1]. -- Christoph [1] http://www.boost.org/doc/libs/1_42_0/doc/html/program_options/howto.html#id1...

Christoph Heindl wrote:
Performs such checking? Like path existing or correctness of IP-address? I cannot find it in your documentation. May be I badly read... Could you tell me, in which documentation's section I may read about this... Thank you.
As far as I know, this feature is called a custom validator and you can read about it in the how-to section of the docs [1].
-- Christoph
[1] http://www.boost.org/doc/libs/1_42_0/doc/html/program_options/howto.html#id1... _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thank you, Christoph! I hope that Vladimir Prus forgive me... Denis

Denis Shevchenko wrote:
Christoph Heindl wrote:
Performs such checking? Like path existing or correctness of IP-address? I cannot find it in your documentation. May be I badly read... Could you tell me, in which documentation's section I may read about this... Thank you.
As far as I know, this feature is called a custom validator and you can read about it in the how-to section of the docs [1].
-- Christoph
[1] http://www.boost.org/doc/libs/1_42_0/doc/html/program_options/howto.html#id1...
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thank you, Christoph!
I hope that Vladimir Prus forgive me...
There's no need to apologise -- it is obviously easier to find a feature in docs if one knows it's there. - Volodya
participants (3)
-
Christoph Heindl
-
Denis Shevchenko
-
Vladimir Prus