Skip to content

Commit 4d2c5dd

Browse files
committed
refactoring to use oop
1 parent 5dd62f3 commit 4d2c5dd

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
99
add_executable(shell ${SOURCE_FILES})
1010

1111
target_link_libraries(shell PRIVATE readline)
12+
13+
include_directories(src)

src/main.cpp

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
1-
#include <iostream>
2-
#include <string>
3-
4-
void do_exit(std::string args) {
5-
int exit_code = std::stoi(args);
6-
exit(exit_code);
7-
}
8-
9-
void do_echo(std::string args) {
10-
std::cout << args << std::endl;
11-
}
1+
#include "shell.h"
122

133
int main() {
14-
// Flush after every std::cout / std:cerr
15-
std::cout << std::unitbuf;
16-
std::cerr << std::unitbuf;
17-
18-
std::string input;
19-
do {
20-
std::cout << "$ ";
21-
std::getline(std::cin, input);
22-
std::string cmd = input.substr(0, input.find(' '));
23-
std::string args = input.substr(input.find(' ') + 1);
24-
if (cmd == "exit") {
25-
do_exit(args);
26-
}
27-
else if (cmd == "echo") {
28-
do_echo(args);
29-
}
30-
else if (input != "") {
31-
std::cout << input << ": command not found" << std::endl;
32-
}
33-
} while(input != "");
4+
Shell shell;
5+
shell.run();
6+
return 0;
347
}

0 commit comments

Comments
 (0)