diff --git a/src/main.cpp b/src/main.cpp index 23b3767..105c326 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include using namespace argument_parser::conventions; @@ -30,6 +31,42 @@ struct argument_parser::parsing_traits::parser_trait { } }; +template<> +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(std::stoi(item)); + } + return result; + } +}; + + +template<> +struct argument_parser::parsing_traits::parser_trait> { + static std::vector parse(const std::string& input) { + std::vector result; + auto copyInput = input; + if (input.starts_with("[")) { + copyInput = input.substr(1, input.size()); + if (copyInput.ends_with("]")) { + copyInput = copyInput.substr(0, copyInput.size() - 1); + } else { + throw std::runtime_error("Invalid vector format. Expected closing ']'."); + } + } + std::stringstream ss(copyInput); + std::string item; + while (std::getline(ss, item, ',')) { + result.push_back(item); + } + return result; + } +}; + const std::initializer_list conventions = { &gnu_argument_convention, &gnu_equal_argument_convention @@ -91,6 +128,10 @@ int main() { }), false); parser.add_argument("p", "point", "Test point", false); + + parser.add_argument>("t", "test", "Test vector", false); + parser.add_argument>("ts", "test-strings", "Test vector", false); + parser.handle_arguments(conventions); auto filename = parser.get_optional("file"); @@ -106,6 +147,22 @@ int main() { parser.display_help(conventions); exit(-1); } + + auto test = parser.get_optional>("test"); + if (test) { + for (auto const& item : test.value()) { + std::cout << item << std::endl; + } + } + + auto test_strings = parser.get_optional>("test-strings"); + if (test_strings) { + for (auto const& item : test_strings.value()) { + std::cout << item << std::endl; + } + } + + return 0; } \ No newline at end of file