diff --git a/.clang-tidy b/.clang-tidy index 9aada7a..446bcfa 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,7 +9,6 @@ Checks: '-checks=-*,bugprone-*,clang-analyzer-*,cppcoreguidelines-*,rea WarningsAsErrors: '' HeaderFilterRegex: '' -AnalyzeTemporaryDtors: false FormatStyle: none CheckOptions: - key: readability-identifier-naming.ClassCase diff --git a/src/example/example.cpp b/src/example/example.cpp index b463ee7..224905a 100644 --- a/src/example/example.cpp +++ b/src/example/example.cpp @@ -1,59 +1,59 @@ #include #include "options/Converters.hpp" -#include "options/Options.hpp" +#include "options/Parser.hpp" int main(int argc, char *argv[]) { using std::cout; using std::endl; - Options::Options opts; + Options::Parser args_parser; - opts.add_flag("help", 'h', "This help is accessible via short and long option"); - opts.add_flag("verbose", 'v', "Verbose - accessible via -v and --verbose"); - opts.add_optional( + args_parser.add_flag("help", 'h', "This help is accessible via short and long option"); + args_parser.add_flag("verbose", 'v', "Verbose - accessible via -v and --verbose"); + args_parser.add_optional( "level", "Debug level, one of none, debug, error - it is checked by the validator", "none", [](const std::string &value) { return (value == "none" || value == "debug" || value == "error"); }); - opts.add_mandatory("config", 'c', "Configuration file"); - opts.add_optional("int", 'i', "Some small integer in range <-10..10> as checked by validator", "4", - [](const std::string &value) { - int32_t num = Options::as_int(value); - return num >= -10 && num <= 10; // NOLINT - }); - opts.add_optional("double", 'd', "Double value > 3.0", "3.14", [](const std::string &value) { + args_parser.add_mandatory("config", 'c', "Configuration file"); + args_parser.add_optional("int", 'i', "Some small integer in range <-10..10> as checked by validator", "4", + [](const std::string &value) { + int32_t num = Options::as_int(value); + return num >= -10 && num <= 10; // NOLINT + }); + args_parser.add_optional("double", 'd', "Double value > 3.0", "3.14", [](const std::string &value) { double num = Options::as_double(value); return num > 3.0; // NOLINT }); - opts.add_optional("bf", "Boolean value", "false"); - opts.add_optional("bt", "Boolean value", "true"); + args_parser.add_optional("bf", "Boolean value", "false"); + args_parser.add_optional("bt", "Boolean value", "true"); - if (!opts.parse(argc, argv) || opts.as_bool("help")) + if (!args_parser.parse(argc, argv) || args_parser.as_bool("help")) { cout << "Usage: " << argv[0] << " [options] [-- [positional arguments]]" << endl; - cout << opts.get_possible_options() << endl; + cout << args_parser.get_possible_options() << endl; return -1; } cout << std::boolalpha; cout << "Options:" << endl; - cout << " verbose : " << opts.as_bool("verbose") << endl; - cout << " level : " << opts.as_string("level") << endl; - cout << " config : " << opts.as_string("config") << endl; - cout << " int : " << opts.as_int("int") << endl; - cout << " double : " << opts.as_double("double") << endl; - cout << " bf : " << opts.as_bool("bf") << endl; - cout << " bt : " << opts.as_bool("bt") << endl; + cout << " verbose : " << args_parser.as_bool("verbose") << endl; + cout << " level : " << args_parser.as_string("level") << endl; + cout << " config : " << args_parser.as_string("config") << endl; + cout << " int : " << args_parser.as_int("int") << endl; + cout << " double : " << args_parser.as_double("double") << endl; + cout << " bf : " << args_parser.as_bool("bf") << endl; + cout << " bt : " << args_parser.as_bool("bt") << endl; // positional arguments are all the strings after "--" separator, for example: // ./example -c config_file.txt -v -- these strings are positional arguments - if (opts.positional_count() > 0) + if (args_parser.positional_count() > 0) { cout << "Positional parameters:" << endl; - for (size_t i = 0; i < opts.positional_count(); ++i) - cout << " [" << i << "]: " << opts.positional(i) << endl; + for (size_t i = 0; i < args_parser.positional_count(); ++i) + cout << " [" << i << "]: " << args_parser.positional(i) << endl; } else cout << "No positional parameters." << endl; diff --git a/src/options/CMakeLists.txt b/src/options/CMakeLists.txt index 55ea5d1..ab2e9c5 100644 --- a/src/options/CMakeLists.txt +++ b/src/options/CMakeLists.txt @@ -1,3 +1,3 @@ -add_library(options STATIC Converters.cpp Option.cpp Options.cpp) +add_library(options STATIC Converters.cpp Option.cpp Parser.cpp) target_include_directories(options PUBLIC ..) target_link_libraries(options PRIVATE options_compile_flags) diff --git a/src/options/Options.cpp b/src/options/Parser.cpp similarity index 78% rename from src/options/Options.cpp rename to src/options/Parser.cpp index d1e1673..de7c7fe 100644 --- a/src/options/Options.cpp +++ b/src/options/Parser.cpp @@ -5,11 +5,11 @@ #include #include "Option.hpp" -#include "Options.hpp" +#include "Parser.hpp" namespace Options { - struct Options::Impl + struct Parser::Impl { // This will throw an exception if the option is not found. std::vector