38 lines
920 B
C++
38 lines
920 B
C++
#pragma once
|
|
|
|
#include <array>
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <unordered_map>
|
|
#include <memory>
|
|
|
|
#include "ast/ast.hpp"
|
|
#include "cmd/args/arg.hpp"
|
|
|
|
namespace fsh {
|
|
|
|
class Command {
|
|
|
|
using FlagNode = std::optional<std::string>&;
|
|
using ArgNodes = std::vector<std::shared_ptr<CommandArgumentNode> >;
|
|
|
|
public:
|
|
void execute(FlagNode flag, ArgNodes& vec, std::istream& in, std::ostream& out);
|
|
|
|
template <typename T>
|
|
static std::unique_ptr<Command> register_cmd() {
|
|
std::unique_ptr<Command> cmd = std::make_unique<T>();
|
|
cmd->register_flags();
|
|
return cmd;
|
|
}
|
|
|
|
protected:
|
|
virtual void register_flags() {};
|
|
virtual void run(std::istream& in, std::ostream& out, ArgManager& args) {};
|
|
ArgFactory& get_factory() { return arg_factory; }
|
|
|
|
private:
|
|
ArgFactory arg_factory;
|
|
};
|
|
|
|
} |