diff --git a/CMakeLists.txt b/CMakeLists.txt index fc3a00b..a1cf353 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,4 +16,6 @@ include_directories(src/headers/conventions/implementations) include_directories(src/headers/parser/platform_headers) include_directories(src/headers/parser/parsing_traits) -add_executable(test src/main.cpp) \ No newline at end of file +file(GLOB_RECURSE SRC_FILES "src/source/*.cpp" "src/source/**/*.cpp" "src/source/**/**/*.cpp") + +add_executable(test src/main.cpp ${SRC_FILES}) \ No newline at end of file diff --git a/src/headers/conventions/base_convention.hpp b/src/headers/conventions/base_convention.hpp index fc7d555..96dc59e 100644 --- a/src/headers/conventions/base_convention.hpp +++ b/src/headers/conventions/base_convention.hpp @@ -27,9 +27,8 @@ namespace argument_parser::conventions { } // namespace argument_parser::conventions namespace argument_parser::conventions::helpers { - static std::string to_lower(std::string s); - - static std::string to_upper(std::string s); + std::string to_lower(std::string s); + std::string to_upper(std::string s); } // namespace argument_parser::conventions::helpers #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a33bd5c..51722d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,6 @@ #define ALLOW_DASH_FOR_WINDOWS 0 #include -#include #include #include #include @@ -10,7 +9,6 @@ #include #include - struct Point { int x, y; }; @@ -45,6 +43,18 @@ template <> struct argument_parser::parsing_traits::parser_trait struct argument_parser::parsing_traits::parser_trait> { + static std::vector parse(const std::string &input) { + std::vector result; + std::stringstream ss{input}; + std::string item; + while (std::getline(ss, item, ',')) { + result.push_back(item); + } + return result; + } +}; + const std::initializer_list conventions = { &argument_parser::conventions::gnu_argument_convention, &argument_parser::conventions::gnu_equal_argument_convention, @@ -154,14 +164,17 @@ int v2Examples() { using namespace argument_parser::v2::flags; argument_parser::v2::base_parser parser; - parser.add_argument({{ShortArgument, "e"}, {LongArgument, "echo"}, {Action, echo}}); + parser.add_argument( + {{ShortArgument, "e"}, {LongArgument, "echo"}, {Action, echo}, {HelpText, "echoes given variable"}}); - parser.add_argument({{ShortArgument, "ep"}, {LongArgument, "echo-point"}, {Action, echo_point}}); + parser.add_argument( + {{ShortArgument, "ep"}, {LongArgument, "echo-point"}, {Action, echo_point}, {HelpText, "echoes given point"}}); parser.add_argument({ // stores string for f/file flag {ShortArgument, "f"}, {LongArgument, "file"}, + {HelpText, "File to grep, required only if using grep"}, // if no action, falls to store operation with given type. }); @@ -169,10 +182,12 @@ int v2Examples() { // stores string for g/grep flag {ShortArgument, "g"}, {LongArgument, "grep"}, + {HelpText, "Grep pattern, required only if using file"}, // same as 'file' flag }); - parser.add_argument({{ShortArgument, "c"}, {LongArgument, "cat"}, {Action, cat}}); + parser.add_argument( + {{ShortArgument, "c"}, {LongArgument, "cat"}, {Action, cat}, {HelpText, "Prints the content of the file"}}); parser.add_argument({ // { ShortArgument, "sp" }, // now if ShortArgument or LongArgument is missing, it will use it for the other. diff --git a/src/source/conventions/base_convention.cpp b/src/source/conventions/base_convention.cpp index debbfda..b8e483d 100644 --- a/src/source/conventions/base_convention.cpp +++ b/src/source/conventions/base_convention.cpp @@ -2,12 +2,12 @@ #include namespace argument_parser::conventions::helpers { - static std::string to_lower(std::string s) { + std::string to_lower(std::string s) { std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); }); return s; } - static std::string to_upper(std::string s) { + std::string to_upper(std::string s) { std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::toupper(c); }); return s; } diff --git a/src/source/parser/argument_parser.cpp b/src/source/parser/argument_parser.cpp index dcbbf61..c4eaa73 100644 --- a/src/source/parser/argument_parser.cpp +++ b/src/source/parser/argument_parser.cpp @@ -27,6 +27,10 @@ namespace argument_parser { return *this; } + bool argument::expects_parameter() const { + return action->expects_parameter(); + } + bool argument::is_required() const { return required; } @@ -181,13 +185,13 @@ namespace argument_parser { std::initializer_list convention_types) { std::vector> required_args; for (auto const &[key, arg] : argument_map) { - if (arg.is_required() and not arg.is_invoked()) { + if (arg.is_required() && !arg.is_invoked()) { required_args.emplace_back>( {reverse_short_arguments[key], reverse_long_arguments[key]}); } } - if (not required_args.empty()) { + if (!required_args.empty()) { std::cerr << "These arguments were expected but not provided: "; for (auto const &[s, l] : required_args) { std::cerr << "[-" << s << ", --" << l << "] ";