Initial commit
This commit is contained in:
41
include/cmd/cmd_base.hpp
Normal file
41
include/cmd/cmd_base.hpp
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
#include "ast/ast.hpp"
|
||||
#include "cmd/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;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user