diff --git a/include/parser/argument_parser.hpp b/include/parser/argument_parser.hpp index f1abab0..239a6c2 100644 --- a/include/parser/argument_parser.hpp +++ b/include/parser/argument_parser.hpp @@ -150,6 +150,11 @@ namespace argument_parser { base_add_argument(short_arg, long_arg, help_text, action, required); } + template + void add_argument(std::string const& short_arg, std::string const& long_arg, std::string const& help_text, bool required) { + base_add_argument(short_arg, long_arg, help_text, required); + } + void add_argument(std::string const& short_arg, std::string const& long_arg, std::string const& help_text, non_parametered_action const& action, bool required) { base_add_argument(short_arg, long_arg, help_text, action, required); } @@ -157,16 +162,14 @@ namespace argument_parser { void add_argument(std::string const& short_arg, std::string const& long_arg, std::string const& help_text, bool required) { base_add_argument(short_arg, long_arg, help_text, required); } - - template - void add_argument(std::string const& short_arg, std::string const& long_arg, std::string const& help_text, bool required) { - base_add_argument(short_arg, long_arg, help_text, required); - } template std::optional get_optional(std::string const& arg) { auto id = find_argument_id(arg); - if (id.has_value()) return std::any_cast(stored_arguments[id.value()]); + if (id.has_value()) { + auto value = stored_arguments[id.value()]; + if (value.has_value()) return std::any_cast(value); + } return std::nullopt; } diff --git a/src/main.cpp b/src/main.cpp index b9e2b90..4e85dfa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -105,10 +105,9 @@ auto make_grep_action(argument_parser::base_parser& parser) { } int main() { - // std::vector fake_args = { "-g", "add", "-f", "src/main.cpp", "-ep", "1,2" }; - // auto parser = argument_parser::fake_parser{"test", std::move(fake_args)}; auto parser = argument_parser::parser{}; auto [file, grep] = make_grep_action(parser); + parser.add_argument("e", "echo", "echoes given variable", echo, false); parser.add_argument("ep", "echo-point", "echoes given point", echo_point, false); parser.add_argument("f", "file", "File to grep, required only if using grep", file, false);