| 3 | #include <cstdlib.hpp> |
| 4 | |
| 5 | extern "C" void _start() { |
| 6 | // implement a simple cli |
| 7 | std::cout << "Welcome to WasmOS CLI" << std::endl; |
| 8 | std::cout << "Type 'help' to see built-in commands" << std::endl; |
| 9 | |
| 10 | while (true) { |
| 11 | std::cout << "> "; |
| 12 | char command[100]; |
| 13 | std::cin >> command; |
| 14 | |
| 15 | if (std::strcmp(command, "exit") == 0) { |
| 16 | break; |
| 17 | } else if (std::strcmp(command, "help") == 0) { |
| 18 | std::cout << "Built-in commands:" << std::endl; |
| 19 | std::cout << "help - show available commands" << std::endl; |
| 20 | std::cout << "exit - exit the CLI" << std::endl; |
| 21 | } else { |
| 22 | int returncode = std::system(command); |
| 23 | if (returncode == -1) { |
| 24 | std::cout << "Command not found" << std::endl; |
| 25 | } else if (returncode == -2) { |
| 26 | std::cout << "System error running command." << std::endl; |
| 27 | } else if (returncode != 0) { |
| 28 | std::cout << "Command returned with error code " << returncode << std::endl; |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | } |