-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommand.h
139 lines (107 loc) · 3.18 KB
/
Command.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef COMMAND_H
#define COMMAND_H
#include "Redirection.h"
#include <string>
#include <vector>
#include <sstream>
class Command {
public:
virtual ~Command() {}
Command(std::string commandName, std::string opt, std::string arg, std::vector<Redirection> streams) : name(commandName), option(opt), argument(arg), streams(streams), buffer(nullptr) {}
virtual void execute() = 0;
virtual void print(std::string output) = 0;
void setBuffer(std::stringstream* buffer);
std::string getBuffer();
std::string getName();
std::vector<Redirection> getStreams();
protected:
bool RedirectInput(std::string& input);
bool RedirectOutput(std::string input);
std::string getArgumentType();
std::string ifArgumentEmpty();
std::string ifBufferNotEmpty();
std::string name;
std::string option;
std::string argument;
std::vector<Redirection> streams;
std::stringstream* buffer;
};
class Echo : public Command {
public:
Echo(std::string arg, std::vector<Redirection> streams) : Command("echo", "", arg, streams) {};
void execute();
void print(std::string output);
};
class Prompt : public Command {
public:
Prompt(std::string arg, std::vector<Redirection> streams) : Command("prompt", "", arg, streams) {};
static std::string getPromptSign();
void execute();
void print(std::string output) {};
private:
static std::string promptSign;
};
class Time : public Command {
public:
Time(std::vector<Redirection> streams) : Command("time", "", "", streams) {}
void execute();
void print(std::string output);
};
class Date : public Command {
public:
Date(std::vector<Redirection> streams) : Command("date", "", "", streams) {}
void execute();
void print(std::string output);
};
class Touch : public Command {
public:
Touch(std::string arg, std::vector<Redirection> streams) : Command("touch", "", arg, streams) {}
void execute();
void print(std::string output) {};
};
class Truncate : public Command {
public:
Truncate(std::string arg, std::vector<Redirection> streams) : Command("truncate", "", arg, streams) {}
void execute();
void print(std::string output) {};
};
class Rm : public Command {
public:
Rm(std::string arg, std::vector<Redirection> streams) : Command("rm", "", arg, streams) {}
void execute();
void print(std::string output) {};
};
class Wc : public Command {
public:
Wc(std::string opt, std::string arg, std::vector<Redirection> streams) : Command("wc", opt, arg, streams) {}
void execute();
void print(std::string output);
};
class Tr : public Command {
public:
Tr(std::string arg, std::vector<Redirection> streams) : Command("tr", "", arg, streams) {
parseArguments(arg);
}
void execute();
void print(std::string output);
std::string getWhat();
std::string getWith();
private:
std::string what;
std::string with;
void checkBuffer();
void parseArguments(std::string arg);
};
class Head : public Command {
public:
Head(std::string opt, std::string arg, std::vector<Redirection> streams) : Command("head", opt, arg, streams) {}
void execute();
void print(std::string output);
};
class Batch : public Command {
public:
Batch(std::string arg, std::vector<Redirection> streams) : Command("batch", "", arg, streams) {}
void execute();
void print(std::string output) {};
};
#endif