A modular, object-oriented command-line shell built in C++ — clean architecture, beginner-friendly, and easily extensible.
cpp-cli-shell is a lightweight interactive shell implemented in C++ using object-oriented principles. It demonstrates clean separation of concerns — parsing, command handling, file operations, and utilities are each isolated into their own modules, making the codebase easy to understand, maintain, and extend.
Built as a learning project to explore C++ OOP, modular design patterns, and CLI application development.
| Feature | Description |
|---|---|
| 🔁 Interactive Shell Loop | Continuously reads and executes user commands |
| 🔍 Input Tokenizer | Parses raw input into structured command tokens |
| ➕ Arithmetic | add command for integer addition |
| 📄 File Reader | read command to display file contents |
| 🔎 Text Search | search command to find words inside files |
| 🧩 Modular Architecture | Clean OOP design — each concern in its own class |
cpp-cli-shell/
├── main.cpp # Shell entry point — runs the input loop
├── parser.h/.cpp # Tokenizes raw input into command + args
├── commands.h/.cpp # Dispatches and handles all commands
├── file_ops.h/.cpp # File reading and word search logic
└── utils.h/.cpp # String utilities (trim, helpers)
- A C++ compiler (
g++,clang++, or MSVC) - C++17 or later
# Clone the repository
git clone https://github.com/ashish7802/cpp-cli-shell.git
cd cpp-cli-shell
# Compile
g++ main.cpp parser.cpp commands.cpp file_ops.cpp utils.cpp -o cli_shellLinux / macOS:
./cli_shellWindows (PowerShell):
.\cli_shell.exehello → Prints a greeting message
add <a> <b> → Adds two integers (e.g. add 5 3 → 8)
read <filename> → Displays the contents of a file
search <filename> <word> → Searches for a word inside a file
exit → Exits the shell
Example session:
shell> hello
Hello, World!
shell> add 10 25
Result: 35
shell> read notes.txt
This is the content of notes.txt...
shell> search notes.txt hello
Found: 'hello' in notes.txt
shell> exit
Goodbye!
The project follows a clean separation of concerns pattern:
Parser— Responsible only for breaking raw input into tokensCommandHandler— Routes tokens to the correct command handlerFileOps— Encapsulates all file I/O logicUtils— Stateless helper functions (string trimming, etc.)main.cpp— Thin orchestration layer that wires everything together
This makes adding new commands as simple as adding a new handler in commands.cpp — no other files need to change.
To add a new command:
- Add a private handler method in
commands.h - Implement it in
commands.cpp - Register it in the
execute()dispatch block
// commands.cpp — add inside execute()
else if (tokens[0] == "mycommand") {
handle_mycommand(tokens);
}This project is licensed under the MIT License.
Ashish Yadav
- GitHub: @ashish7802
- Portfolio: ashyada.netlify.app
⭐ If you found this useful, drop a star — it helps!