Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Command-Line-Interpreter

Java Maven JUnit CLI

🚀 Overview

Command-Line-Interpreter is a lightweight, Java-based shell that implements common UNIX-style commands (pwd, cd, ls, mkdir, rmdir, touch, mv, rm, cat), supports output redirection (> and >>), and runs entirely in-process without external dependencies.

✨ Features

  • Built-in Commandspwd, cd, ls (with -a, -r), mkdir, rmdir, touch, mv, rm, cat
  • I/O Redirection> to overwrite and >> to append output to files
  • Custom Prompt – Displays the current working directory
  • Parser Module – Splits input into a command and arguments
  • Graceful Error Handling – Informative messages for invalid usage or missing files/directories
  • Unit Tested – Each command has its own JUnit 5 test file

📂 Project Structure

command-line-Interpreter/
├── src/
│   ├── main/
│   │   └── java/
│   │       └── cli/
│   │           ├── Main.java                # Entry point, launches Terminal
│   │           ├── Parser.java              # Parses raw input into command + args
│   │           └── Terminal.java            # Implements built-in commands & interface loop
│   └── test/
│       └── java/
│           └── cli/
│               ├── AppendToAFileTest.java
│               ├── CatTest.java
│               ├── CdTest.java
│               ├── LsTest.java
│               ├── MkdirTest.java
│               ├── MvTest.java
│               ├── PwdTest.java
│               ├── RmTest.java
│               ├── RmdirTest.java
│               ├── TouchTest.java
│               └── WriteToAFileTest.java      # Tests for > and >> functionality
├── .gitignore
├── pom.xml                        # Maven configuration and dependencies
└── README.md                      # Project documentation

🛠️ Tech Stack

  • Language: Java 17
  • Build: Maven
  • Testing: JUnit 5

⚡ Installation & Setup

Prerequisites

  • Java 17 or higher
  • Maven 3.x

Steps

  1. Clone the repository

    git clone https://github.com/Hemdan47/command-line-Interpreter.git
    cd command-line-Interpreter
  2. Build & test

    mvn clean verify
  3. Run the shell

    mvn exec:java -Dexec.mainClass=cli.Main

    You’ll see a prompt showing your current working directory, for example:

    /home/user/command-line-Interpreter > 
    

🔧 How It Works

📝 Parsing

  • Parser splits the input line on whitespace.
  • The first token becomes the command, the rest are arguments.

🖥️ Terminal Loop

  • Displays the current directory as the prompt.
  • Reads a line, invokes Parser.parse().
  • Calls the corresponding method (pwd(), cd(args), ls(args), etc.).
  • Handles redirection tokens (> and >>) by capturing output and writing/appending to files.
  • Prints command output or error messages.

📂 Command Implementations

  • pwd – prints the absolute path of the current directory.
  • cd [dir] – changes directory; errors on missing, invalid, or non-directory targets.
  • ls [-a|-r] – lists files:
    • no flag: visible files only
    • -a: include hidden
    • -r: reverse order
  • mkdir [dirs...] – creates one or more directories.
  • rmdir [dirs...] – removes empty directories only.
  • touch [files...] – creates new empty files.
  • mv [src] [dest] – moves or renames files/directories.
  • rm [files...] – deletes files only (not directories).
  • cat [files...] – prints file contents; errors on directories or missing files.
  • >, >> – redirect standard output to a file (overwrite or append).

📖 Usage

/home/user/command-line-Interpreter > pwd
/home/user/command-line-Interpreter
/home/user/command-line-Interpreter > ls -a
. .. src pom.xml
/home/user/command-line-Interpreter > mkdir test
/home/user/command-line-Interpreter > cd test
/home/user/command-line-Interpreter/test > touch hello.txt
/home/user/command-line-Interpreter/test > echo "Hello World" > hello.txt
/home/user/command-line-Interpreter/test > cat hello.txt
Hello World
/home/user/command-line-Interpreter/test > exit

💻 Development

  • Run tests
    mvn test

📝 License

This project is open source and available under the MIT License.

About

Command-Line-Interpreter is a lightweight, Java-based shell that implements common UNIX-style commands (pwd, cd, ls, mkdir, rmdir, touch, mv, rm, cat), supports output redirection (> and >>), and runs entirely in-process without external dependencies.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages