From a62cd661611b4c90b5ebe70f6f466f04a7f98684 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Thu, 21 May 2015 00:32:25 +0200 Subject: [PATCH] Provide more complex example and describe more usage. --- README | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+) diff --git a/README b/README index b7121a2..cb2c84f 100644 --- a/README +++ b/README @@ -54,6 +54,99 @@ Now program can be compiled & run using following commands: $ ./a.out -h Help information +### Possible classes to use: + +Arguments are non-named program parameters. They must have some description and +function handling when argument is passed: + + new Argument("Bool argument", [](bool value) { }); + +Options are named program parameters. Option need name (e.g.: "i"), description, +and function. + + new Option("name", "Integer option", [](int value) { }); + +Options could also be set as containing no value. In that case they become just +a simple switches (some kind of mix between Argument and Option). They are used +just to invoke some function if specific name was passed: + + new Option("v", "Verbose mode of program", [](void) { }); + +### Behaviours + +Parameters (Options and Arguments) can also be wrapped in Behaviours. + +Required behaviour - if specific parameter was not passed and is required, +exception is thrown (missingRequiredParameter): + + new Required( + new Argument("Bool argument", [](bool value) { }) + ); + +MultiValue behaviour - given parameter can handle more than one value. Values are +separated by given separator. For each value passed function is invoked: + + new MultiValue(",", + new Option("input", "Input file", [](std::string value) { }) + ) + +More complex example: + (...) + void argument_function(bool a) { + std::cout << "Argument: " << a << std::endl; + } + + void option_function(std::string a) { + std::cout << "Option function " << a << std::endl; + } + + void void_function(void) { + std::cout << "Void function " << std::endl; + } + + Command command(argc, argv, { + new Required( + new MultiValue("-", + new Argument("Input values", argument_function) + ) + ), + new MultiValue(",", + new Option("f", "Optional file", option_function) + ) + new Option("h", "Help", void_function) + }); + (...) + +Above code allows us to: + +Parameters wrapped in Required class, have validator which checks if argument + $ ./a.out + *Input values* is required + + $ ./a.out 1 + Argument: 1 + + $ ./a.out 0 + Argument: 0 + + $ ./command 0 f + Option: f requires value to be specified after equal sign, but no equal sign was found + + $ ./command 0 f= + Option: f failed value conversion to the required type + +For MultiValue Parameters each value is passed to the given function: + $ ./a.out 1-0-1 + Argument: 1 + Argument: 0 + Argument: 1 + + $ ./command 0 f=one,two,three + Argument: 0 + Option function one + Option function two + Option function three + ## Documentation Current documentation can be found at: diff --git a/README.md b/README.md index b7121a2..cb2c84f 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,99 @@ Now program can be compiled & run using following commands: $ ./a.out -h Help information +### Possible classes to use: + +Arguments are non-named program parameters. They must have some description and +function handling when argument is passed: + + new Argument("Bool argument", [](bool value) { }); + +Options are named program parameters. Option need name (e.g.: "i"), description, +and function. + + new Option("name", "Integer option", [](int value) { }); + +Options could also be set as containing no value. In that case they become just +a simple switches (some kind of mix between Argument and Option). They are used +just to invoke some function if specific name was passed: + + new Option("v", "Verbose mode of program", [](void) { }); + +### Behaviours + +Parameters (Options and Arguments) can also be wrapped in Behaviours. + +Required behaviour - if specific parameter was not passed and is required, +exception is thrown (missingRequiredParameter): + + new Required( + new Argument("Bool argument", [](bool value) { }) + ); + +MultiValue behaviour - given parameter can handle more than one value. Values are +separated by given separator. For each value passed function is invoked: + + new MultiValue(",", + new Option("input", "Input file", [](std::string value) { }) + ) + +More complex example: + (...) + void argument_function(bool a) { + std::cout << "Argument: " << a << std::endl; + } + + void option_function(std::string a) { + std::cout << "Option function " << a << std::endl; + } + + void void_function(void) { + std::cout << "Void function " << std::endl; + } + + Command command(argc, argv, { + new Required( + new MultiValue("-", + new Argument("Input values", argument_function) + ) + ), + new MultiValue(",", + new Option("f", "Optional file", option_function) + ) + new Option("h", "Help", void_function) + }); + (...) + +Above code allows us to: + +Parameters wrapped in Required class, have validator which checks if argument + $ ./a.out + *Input values* is required + + $ ./a.out 1 + Argument: 1 + + $ ./a.out 0 + Argument: 0 + + $ ./command 0 f + Option: f requires value to be specified after equal sign, but no equal sign was found + + $ ./command 0 f= + Option: f failed value conversion to the required type + +For MultiValue Parameters each value is passed to the given function: + $ ./a.out 1-0-1 + Argument: 1 + Argument: 0 + Argument: 1 + + $ ./command 0 f=one,two,three + Argument: 0 + Option function one + Option function two + Option function three + ## Documentation Current documentation can be found at: -- 2.30.2