Skip to content

Feat: Implement 'cls' command using native OS calls - #79

Merged
anshumanjadiya1102 merged 2 commits into
Drive-for-Java:mainfrom
HossamSaberr:feature/cls-command
Oct 27, 2025
Merged

anshumanjadiya1102 merged 2 commits into
Drive-for-Java:mainfrom
HossamSaberr:feature/cls-command

Conversation

@HossamSaberr

@HossamSaberr HossamSaberr commented Oct 27, 2025

Copy link
Copy Markdown
Member

Hi! This PR adds the implementation for the cls command.

It uses ProcessBuilder to call the native OS command (cls on Windows, clear on macOS/Linux). This provides a true screen-clearing functionality as discussed in the issue.

Closes #6

Summary by CodeRabbit

  • New Features
    • Added "cls" command for clearing the console screen
    • Implemented native OS-level clear-screen functionality supporting Windows and Unix-like systems
    • Enhanced error handling for clear-screen operations with improved interrupt signal management

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Hi @HossamSaberr!

Thank you for contributing to MyCMD. A maintainer will review your PR shortly. 🎉

@coderabbitai

coderabbitai Bot commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A "cls" command is added to clear the console screen using native OS methods (cmd /c cls for Windows, clear for Unix-like systems). The command is registered in the CLI registry with exception handling for execution failures. However, the registration appears duplicated in App.java.

Changes

Cohort / File(s) Summary
CLI Command Registry
src/main/java/com/mycmd/App.java
Registers the new "cls" command to the command dispatcher. Registration occurs twice within registerCommands method, resulting in duplicate entries.
Command Implementation
src/main/java/com/mycmd/commands/ClsCommand.java
Implements ClsCommand with platform-specific OS-native clear functionality. Replaces a 50-blank-line workaround with Runtime.exec() calls. Includes exception handling for InterruptedException and IOException with error messaging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Attention needed: Duplicate "cls" registration in App.java must be removed; only one registration should remain
  • Platform-specific execution: Runtime.exec() calls warrant verification for proper shell command handling on Windows and Unix-like systems
  • Exception handling: Verify InterruptedException restoration and IOException messaging are appropriate for user feedback

Poem

🐰 A rabbit hops through cluttered screens,
With blessed "cls" to clear the mess,
Cross-platform magic, clean and lean,
Though twice registered—needs finesse!
Thumper approves of organized command lines 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Feat: Implement 'cls' command using native OS calls" accurately and specifically describes the main change in the pull request. It clearly communicates that the cls command is being added to the CLI with a focus on using native OS commands (via ProcessBuilder) rather than a simple newline-printing approach. The title is concise, specific, and highlights the key technical approach differentiating this implementation.
Linked Issues Check ✅ Passed The pull request successfully implements the coding requirements specified in linked issue #6. The implementation adds a functional cls command to clear the console screen using Java ProcessBuilder to invoke native OS commands (cls on Windows, clear on Unix-like systems). This approach delivers the "more advanced method for better compatibility" explicitly mentioned in the issue requirements. The PR includes error handling for InterruptedException and IOException, properly addressing the need for a robust implementation. The core objective of providing a cls command using appropriate Java methods is fully satisfied.
Out of Scope Changes Check ✅ Passed All code changes in this pull request are directly related to implementing the cls command as specified in linked issue #6. The modifications include the ClsCommand implementation using ProcessBuilder for native OS calls and the registration of the command in App.java's registerCommands method. There are no changes to unrelated functionality, third-party integrations, or features outside the scope of the cls command feature. However, the AI summary notes duplicate registrations of the cls command in App.java which should be reviewed to ensure no redundancy.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/java/com/mycmd/commands/ClsCommand.java (1)

22-29: Consider validating that no arguments are provided.

The documentation states "This command does not accept any arguments," but the implementation doesn't validate this. Users passing arguments will see them silently ignored, which could be confusing.

Consider adding validation at the start of the execute method:

 @Override
 public void execute(String[] args, ShellContext context) {
+    if (args.length > 0) {
+        System.out.println("'cls' command does not accept any arguments.");
+        return;
+    }
     try {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 45acb7b and bb0ab14.

📒 Files selected for processing (2)
  • src/main/java/com/mycmd/App.java (1 hunks)
  • src/main/java/com/mycmd/commands/ClsCommand.java (1 hunks)
🔇 Additional comments (1)
src/main/java/com/mycmd/commands/ClsCommand.java (1)

23-35: Implementation looks solid.

The OS detection and ProcessBuilder approach is appropriate for invoking native clear-screen commands. The use of inheritIO() ensures the command interacts with the actual terminal, and waitFor() properly blocks until completion. Exception handling correctly restores the interrupted status for InterruptedException and provides user feedback for failures.

Comment thread src/main/java/com/mycmd/App.java Outdated
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Hi @HossamSaberr!

Thank you for contributing to MyCMD. A maintainer will review your PR shortly. 🎉

@anshumanjadiya1102 anshumanjadiya1102 added hacktoberfest-accepted This is for Hacktoberfest hacktoberfest This is for Hacktoberfest and removed needs-review labels Oct 27, 2025
@anshumanjadiya1102
anshumanjadiya1102 merged commit 16c762d into Drive-for-Java:main Oct 27, 2025
4 checks passed
@anshumanjadiya1102

Copy link
Copy Markdown
Member

I merged it. Thanks for Contributing here @HossamSaberr. And now you can join our org too. You are invited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from-fork hacktoberfest This is for Hacktoberfest hacktoberfest-accepted This is for Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Implement 'cls' Command to Clear Console

2 participants