How benaliossama/0-shell works
Project type and purpose
• This is a command-line shell implementation in Rust.
• It consists of modules for parsing user input, executing commands (both built-in and external), and the top‐level “shell” binary that ties everything together.
File structure
• Top-level crates:
• parsing/ (lexing & parsing user input)
• executer/ (dispatching and running commands)
• shell/ (the interactive shell REPL)
• commands/ (definitions of built-in commands and sub-crates for external-like utilities)
• tools/ls (an example standalone utility)
• bin/ls – another example of shipping a binary (similar to tools/ls).
• Cargo.toml at root – workspace manifest tying all sub‐crates together.
Key excerpts from the README
• Very minimal: “for now, make then make build.”
Main components
a. REPL (shell/) – reads user input, displays prompt, sends raw input downstream
b. Parser (parsing/) – lexes and parses the raw input into an AST or command structure
c. Executor (executer/) – takes the parsed structure and:
• dispatches to built-in commands (commands/src/builtin)
• forks and executes external binaries (tools/ls, commands/src/bin/ls, system PATH)
d. Built-in commands module (commands/src/builtin) – cd, clear, echo, exit, pwd, etc.
e. External commands sub-crates (commands/src/bin/ls, tools/ls, bin/ls) – example utilities published or vendored in the workspace
f. Operating System / File System – underlying environment for external command execution
Relationships & data flow
• REPL → Parser: raw text
• Parser → Executor: parsed AST/command struct
• Executor → Built-ins: direct function calls (in-process)
• Executor → External: spawn child processes via OS APIs
• Executor → REPL: return status code / stdout / stderr for display
• REPL → User: display prompt, command output
Architectural patterns & design principles
• Modular crate separation per concern (parsing, execution, commands, shell UI)
• Workspace structure for shared code and consistent builds
• Clear separation between built-in (in-process) and external (out-of-process) commands
• Single responsibility: each crate handles one layer of the shell pipeline
Relevant technologies, frameworks, libraries
• Rust & Cargo workspaces
• Standard library for I/O, process spawning
• Custom parser module in parsing/
• In-process command dispatch in executer/
• [ ] Each component clearly labeled (with crate path)
• [ ] Layer separation (UI layer, parsing layer, execution layer)