refactor(parser): replace variant-based actions with polymorphic interface

Simplify action handling by introducing a polymorphic base class for actions
Remove std::variant usage and improve type safety with proper cloning
Clean up unused includes and test code in main.cpp
This commit is contained in:
2025-10-04 00:29:00 +04:00
parent 179f5e5d1b
commit 6c3adc3dda
2 changed files with 75 additions and 44 deletions

View File

@@ -1,12 +1,9 @@
#include "argument_parser.hpp"
#include "fake_parser.hpp"
#include <argparse>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <memory>
#include <utility>
#include <vector>
using namespace argument_parser::conventions;
@@ -108,8 +105,9 @@ auto make_grep_action(argument_parser::base_parser& parser) {
}
int main() {
std::vector<std::string> fake_args = { "-g", "add", "-f", "src/main.cpp", "-ep", "1,2" };
auto parser = argument_parser::fake_parser{"test", std::move(fake_args)};
// std::vector<std::string> 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);