Skip to content

MuhammadAliAsgher/JCLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ–₯️ JCLI - Java Command Line Interface

Typing SVG

Java Maven License: MIT Build Status

🌟 If you find this project helpful, please consider giving it a star!

Your support helps others discover this project and motivates continued development.


πŸš€ A Powerful Unix-like CLI Built with Modern Java

JCLI combines the familiarity of traditional shell commands with robust Java architecture, comprehensive testing, and cross-platform compatibility.


πŸš€ Project Overview

JCLI is a comprehensive CLI shell implementation that recreates essential Unix/Linux commands in pure Java. It features a modular architecture, extensive testing suite, and advanced capabilities like command piping, output redirection, aliases, and persistent configuration.


✨ Key Highlights

πŸ”₯ 20+ Built-in Commands
Complete implementation of essential CLI tools

πŸ”— Command Pipeline Support
Unix-style piping with | operator

πŸ“€ Output Redirection
Redirect command output to files with >

βš™οΈ Persistent Configuration
Aliases and settings stored in ~/.clirc

πŸ“š Command History
Full history tracking with search capabilities

πŸ›‘οΈ Path Security
Built-in protection against directory traversal attacks

🌐 Cross-Platform
Runs on Windows, Linux, and macOS

⚑ Native Compilation
GraalVM support for fast, native executables

πŸ“‹ Features

Core Commands

Command Syntax Description
help help [command] Show all commands or help for specific command
echo echo [args] Print arguments to console
pwd pwd Print current working directory
cd cd [dir] Change directory (default: home)
ls ls [-r -l -a] List directory contents with options
cp cp [-r -i] [src] [dest] Copy files/directories
mv mv [-i] [src] [dest] Move/rename files
mkdir mkdir [dir] Create directory
rmdir rmdir [dir] Remove empty directory
rm rm [file] Remove file
rm -r rm -r [dir] Remove directory recursively
touch touch [file] Create empty file or update timestamp
cat cat [file] Display file contents
grep grep [-i -n] [pattern] [file] Search text patterns
wc wc [file] Count lines, words, characters
head head [-n N] [file] Display first N lines (default: 10)
tail tail [-n N] [file] Display last N lines (default: 10)
sort sort [-r] [file] Sort lines alphabetically
find find [-name pattern] Find files matching pattern
history history [-c -n N] Show command history
clear clear Clear terminal screen
date date Display current date and time
alias alias [name=command] Create command aliases
exit exit Exit the CLI

Advanced Features

πŸ”— Command Piping

Chain commands together with Unix-style piping:

cat file.txt | grep "pattern" | sort | head -5
find . -name "*.txt" | head -10
ls -l | grep "2024"

πŸ“€ Output Redirection

Redirect command output to files:

echo "Hello World" > output.txt
ls -l > directory_listing.txt
date > timestamp.txt

πŸ”— Command Aliases

Create shortcuts for frequently used commands:

alias ll='ls -l'
alias la='ls -a'
alias grep-java='grep -i java'

βš™οΈ Configuration Management

  • Config file: ~/.clirc stores aliases and prompt settings
  • Persistent aliases: Automatically loaded on startup
  • Custom prompt: Configurable command prompt format

πŸ“š Command History

  • Persistent storage: History saved to ~/.cli_history
  • Search capabilities: history -n 20 shows last 20 commands
  • History clearing: history -c clears all history

πŸ› οΈ Technical Details

Architecture

  • Language: Java 21 with modern features (records, pattern matching, text blocks)
  • Build System: Maven 3.9+ with comprehensive dependency management
  • Logging: SLF4J with Logback for structured logging
  • Testing: JUnit 5 with extensive unit and integration tests
  • Code Coverage: JaCoCo integration for test coverage analysis

Security Features

  • Path Validation: Automatic prevention of directory traversal attacks
  • Safe File Operations: All file operations validate paths against working directory
  • Input Sanitization: Command arguments are properly validated and escaped

Performance & Compatibility

  • Cross-Platform: Native support for Windows, Linux, and macOS
  • Memory Efficient: Optimized for low memory footprint
  • Fast Startup: Sub-second startup time
  • Native Compilation: GraalVM support for native executables

πŸ“¦ Prerequisites

Required Software

Tool Version Verification Command
JDK 21 OpenJDK 21+ java -version
Maven 3.9+ mvn -version
Git Latest git --version

Development Environment

Recommended IDE: VS Code

Install VS Code from code.visualstudio.com with these extensions:

  • Java Extension Pack - Complete Java development support
  • Maven for Java - Maven project management
  • GitLens - Enhanced Git capabilities (optional)

Optional: GraalVM (for native compilation)

  • GraalVM 21 - For creating native executables
  • Enables ultra-fast startup and reduced memory usage

πŸš€ Installation & Setup

1. Install Development Tools

JDK 21 Installation

# Linux (Ubuntu/Debian)
sudo apt install openjdk-21-jdk

# macOS (Homebrew)
brew install openjdk@21

# Windows
# Download from https://adoptium.net/

Maven Installation

# Linux
sudo apt install maven

# macOS
brew install maven

# Windows
# Download from https://maven.apache.org/download.cgi

Git Installation

# Linux
sudo apt install git

# macOS
brew install git

# Windows
# Download from https://git-scm.com/download/win

2. Clone and Build

# Clone the repository
git clone https://github.com/MuhammadAliAsgher/JCLI.git
cd JCLI

# Build the project
mvn clean compile

# Run tests
mvn test

# Create executable JAR
mvn package

# Run the application
java -jar target/JCLI-1.0-SNAPSHOT.jar

3. Development Setup

VS Code Configuration

  1. Open project in VS Code: code .
  2. Install recommended extensions when prompted
  3. VS Code will automatically configure Java classpath and build settings

Maven Integration

  • Compile: mvn compile
  • Test: mvn test
  • Package: mvn package
  • Clean: mvn clean

🎯 Usage Examples

Basic File Operations

# Navigate and explore
pwd
ls -la
cd Documents
mkdir projects
cd projects

# Create and edit files
touch README.md
echo "# My Project" > README.md
cat README.md

Text Processing Pipelines

# Find and filter files
find . -name "*.java" | head -10
ls -l | grep "txt" | sort

# Process file contents
cat logfile.txt | grep "ERROR" | wc
head -20 data.csv | tail -5

Command Aliases

# Create useful shortcuts
alias ll='ls -l'
alias la='ls -a'
alias projects='cd ~/Documents/projects'

# Use aliases
ll
la
projects

History and Navigation

# View command history
history
history -n 10

# Clear screen and history
clear
history -c

πŸ§ͺ Testing

The project includes comprehensive testing coverage:

# Run all tests
mvn test

# Run specific test class
mvn test -Dtest=ShellIntegrationTest

# Generate coverage report
mvn jacoco:report

# View coverage report
open target/site/jacoco/index.html

Test Coverage

  • Unit Tests: Individual command testing with mocks
  • Integration Tests: End-to-end workflow validation
  • Security Tests: Path traversal and input validation
  • Performance Tests: Memory and execution time validation

πŸ”§ Advanced Configuration

Custom Aliases

Edit ~/.clirc to add persistent aliases:

alias ll='ls -l'
alias la='ls -a'
alias grep-java='grep -i java'
prompt=%s $

Environment Variables

  • JCLI_HOME: Override default configuration directory
  • JCLI_HISTORY_SIZE: Set maximum history entries (default: 1000)

Native Compilation (GraalVM)

# Install GraalVM native-image
gu install native-image

# Create native executable
native-image -jar target/JCLI-1.0-SNAPSHOT.jar jcli

# Run native executable
./jcli

🀝 Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository on GitHub
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes with appropriate tests
  4. Commit changes: git commit -m 'Add amazing feature'
  5. Push to branch: git push origin feature/amazing-feature
  6. Open a Pull Request with detailed description

Development Guidelines

  • Follow Java coding standards and conventions
  • Add tests for new features and bug fixes
  • Update documentation for user-facing changes
  • Ensure all tests pass before submitting PR

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by Unix/Linux command-line tools
  • Built with modern Java 21 features
  • Comprehensive testing with JUnit 5
  • Maven build system and dependency management

Typing SVG

⭐ Star this repository if it helped you! Your support makes a difference. ⭐