Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6f21d2d
Update ci.yml
SauravBhowmick Nov 11, 2025
365e4bb
Update build.yml
SauravBhowmick Nov 11, 2025
066fc4a
Update pom.xml
SauravBhowmick Nov 11, 2025
ce0513d
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
e000143
Refactor AssocCommand to use ProcessBuilder
anshumanjadiya1102 Nov 11, 2025
b160eb0
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
a9bff09
Refactor DriverqueryCommand for better process handling
anshumanjadiya1102 Nov 11, 2025
85365e7
Refactor DriverqueryCommand to simplify command list
anshumanjadiya1102 Nov 11, 2025
1e31910
Update ShellContext.java
SauravBhowmick Nov 11, 2025
4b5a9ca
Refactor: Update FcCommand.java
SauravBhowmick Nov 11, 2025
e23aebf
Refactor: Update PathCommand.java
SauravBhowmick Nov 11, 2025
3b9abd4
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
b598a37
Refactor: Update PingCommand.java
SauravBhowmick Nov 11, 2025
56d0488
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
e868dbe
Refactor: 2nd Update PingCommand.java
SauravBhowmick Nov 11, 2025
b3d751d
Refactor: Update ShutdownCommand.java
SauravBhowmick Nov 11, 2025
81073b5
Refactor: Update TelnetCommand.java
SauravBhowmick Nov 11, 2025
b093d0e
Refactor: Update RouteCommand.java
SauravBhowmick Nov 11, 2025
eef7d7e
Refactor: 2nd Update ShutdownCommand.java
SauravBhowmick Nov 11, 2025
f9db5f1
Refactor: 3rd Update PathCommand.java
SauravBhowmick Nov 11, 2025
1e5c46b
Refactor : 3rd Update ShutdownCommand.java
SauravBhowmick Nov 11, 2025
00938d3
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
065cab6
Refactor : 3rd Update TelnetCommand.java
SauravBhowmick Nov 11, 2025
a68b03c
Refactorise Update ShutdownCommand.java to accomodate suggested changes.
SauravBhowmick Nov 11, 2025
ef2c995
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
f993d7c
Refactorization to Update TelnetCommand.java
SauravBhowmick Nov 11, 2025
eec483a
Refactor : Update ShutdownCommand.java
SauravBhowmick Nov 11, 2025
912fd88
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
b455a28
Refactor: Update TelnetCommand.java
SauravBhowmick Nov 11, 2025
d4ea8e7
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
c837e64
Refactor: Update ShutdownCommand.java
SauravBhowmick Nov 11, 2025
6ce9179
Refactor: Update ShellContext.java
SauravBhowmick Nov 11, 2025
7eeb490
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
5f246d2
Refactor: Update MoveCommand.java
SauravBhowmick Nov 11, 2025
87b65ef
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
5e02821
Refactor : Update ShellContext.java
SauravBhowmick Nov 11, 2025
14c8e84
Refactor: Update formatter.yml
SauravBhowmick Nov 11, 2025
1c37f32
Refactor: Update ShellContext.java
SauravBhowmick Nov 11, 2025
9d2f2bc
Apply Spotless formatting
github-actions[bot] Nov 11, 2025
0824de1
Refactor: Update ShellContext.java
SauravBhowmick Nov 11, 2025
5971375
Refactor: Update formatter.yml
SauravBhowmick Nov 11, 2025
98ccb2e
Refactor: Update ShellContext.java
SauravBhowmick Nov 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,45 @@ on:
pull_request:
branches: [ main ]

permissions:
contents: read
pull-requests: read

jobs:
build:
name: 🔨 Build and Package
runs-on: ubuntu-latest

steps:
- name: 🧩 Checkout source code
uses: actions/checkout@v4

- name: ☕ Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: maven


- name: 🔧 Make Maven wrapper executable
run: chmod +x mvnw

- name: 🧰 Build using Maven Wrapper
run: ./mvnw -B clean package

- name: 📦 Upload built JAR artifact
if: success()
uses: actions/upload-artifact@v4
with:
name: MyCMD-GUI
name: MyCMD-GUI-${{ github.sha }}
path: target/*.jar
retention-days: 30

- name: 📊 Upload test results (if any)
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ github.sha }}
path: target/surefire-reports/
retention-days: 7
continue-on-error: true
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Maven local repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Build (Maven)
run: mvn -B -DskipTests=false package

- name: Run tests
run: mvn test -B

- name: Upload build artifact (optional)

- name: Build and Test with Maven
run: mvn -B clean package
# 'package' phase includes: compile → test → package
# Tests run automatically unless -DskipTests=true is specified

- name: Upload build artifact
if: success()
uses: actions/upload-artifact@v4
with:
name: mycmd-build
path: target/*.jar
retention-days: 7 # Auto-cleanup after 7 days
26 changes: 26 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<javafx.version>21</javafx.version>
<spotless.version>2.43.0</spotless.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -55,6 +56,7 @@
</configuration>
</plugin>

<!-- Shade Plugin (for fat jar) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand All @@ -75,6 +77,30 @@
</execution>
</executions>
</plugin>

<!-- Spotless Plugin (Code Formatter) -->
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<java>
<!-- Uses Google's Java format -->
<googleJavaFormat />
</java>
</configuration>
<executions>
<!-- Automatically checks formatting during build -->
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

</project>
26 changes: 12 additions & 14 deletions src/main/java/com/mycmd/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
import com.mycmd.gui.MainApp;
import javafx.application.Application;

/**
* Entry point for MyCMD-GUI.
*/
/** Entry point for MyCMD-GUI. */
public class App {
public static void main(String[] args) {
// Security check to prevent CMD access
String launchedFrom = System.getenv("MYCMD_LAUNCHED");
if (launchedFrom == null || !launchedFrom.equalsIgnoreCase("true")) {
System.out.println("❌ MyCMD-GUI cannot be run directly from CMD.");
System.out.println("➡️ Please use the official launcher (MyCMD.bat).");
return;
}

// Launch JavaFX GUI
Application.launch(MainApp.class, args);
public static void main(String[] args) {
// Security check to prevent CMD access
String launchedFrom = System.getenv("MYCMD_LAUNCHED");
if (launchedFrom == null || !launchedFrom.equalsIgnoreCase("true")) {
System.out.println("❌ MyCMD-GUI cannot be run directly from CMD.");
System.out.println("➡️ Please use the official launcher (MyCMD.bat).");
return;
}

// Launch JavaFX GUI
Application.launch(MainApp.class, args);
}
}
13 changes: 6 additions & 7 deletions src/main/java/com/mycmd/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import java.io.IOException;

/**
* Interfaace for all commands.
* Every command impleements this
*/
/** Interfaace for all commands. Every command impleements this */
public interface Command {
void execute(String[] args, ShellContext context) throws IOException;
String description();
String usage();
void execute(String[] args, ShellContext context) throws IOException;

String description();

String usage();
}
24 changes: 11 additions & 13 deletions src/main/java/com/mycmd/CommandRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
import java.util.HashMap;
import java.util.Map;

/**
* Registers and retrieves commands by name.
*/
/** Registers and retrieves commands by name. */
public class CommandRegistry {
private final Map<String, Command> commands = new HashMap<>();
private final Map<String, Command> commands = new HashMap<>();

public void register(String name, Command cmd) {
commands.put(name.toLowerCase(), cmd);
}
public void register(String name, Command cmd) {
commands.put(name.toLowerCase(), cmd);
}

public Command get(String name) {
return commands.get(name.toLowerCase());
}
public Command get(String name) {
return commands.get(name.toLowerCase());
}

public Map<String, Command> getAll() {
return commands;
}
public Map<String, Command> getAll() {
return commands;
}
}
32 changes: 15 additions & 17 deletions src/main/java/com/mycmd/ConsoleShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@

import java.util.Scanner;

/**
* Developer console mode for debugging.
*/
/** Developer console mode for debugging. */
public class ConsoleShell {

public static void main(String[] args) {
CommandRegistry registry = new CommandRegistry();
ShellContext context = new ShellContext();
ShellEngine engine = new ShellEngine(registry, context);
public static void main(String[] args) {
CommandRegistry registry = new CommandRegistry();
ShellContext context = new ShellContext();
ShellEngine engine = new ShellEngine(registry, context);

Scanner sc = new Scanner(System.in);
System.out.println("MyCMD Developer Console Mode\n(Type 'exit' to quit)");
Scanner sc = new Scanner(System.in);
System.out.println("MyCMD Developer Console Mode\n(Type 'exit' to quit)");

while (true) {
System.out.print("> ");
String input = sc.nextLine();
if (input.equalsIgnoreCase("exit")) break;
engine.execute(input);
}

sc.close();
while (true) {
System.out.print("> ");
String input = sc.nextLine();
if (input.equalsIgnoreCase("exit")) break;
engine.execute(input);
}

sc.close();
}
}
48 changes: 23 additions & 25 deletions src/main/java/com/mycmd/ShellContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,37 @@
import java.util.HashMap;
import java.util.Map;


public class ShellContext {

private File currentDir;
private final Map<String, String> aliases;
private File currentDir;
private final Map<String, String> aliases;

private Scanner scanner;
private Scanner scanner;

public ShellContext() {
this.currentDir = new File(System.getProperty("user.dir"));
this.aliases = new HashMap<>();
}
public ShellContext() {
this.currentDir = new File(System.getProperty("user.dir"));
this.aliases = new HashMap<>();
}

public File getCurrentDir() {
return currentDir;
}
public File getCurrentDir() {
return currentDir;
}

public void setCurrentDir(File dir) {
if (dir != null && dir.exists() && dir.isDirectory()) {
this.currentDir = dir;
}
public void setCurrentDir(File dir) {
if (dir != null && dir.exists() && dir.isDirectory()) {
this.currentDir = dir;
}
}

public Map<String, String> getAliases() {
return aliases;
}
public Map<String, String> getAliases() {
return aliases;
}

public void addAlias(String name, String command) {
aliases.put(name, command);
}
public void addAlias(String name, String command) {
aliases.put(name, command);
}

public String resolveAlias(String cmd) {
return aliases.getOrDefault(cmd, cmd);
}
public String resolveAlias(String cmd) {
return aliases.getOrDefault(cmd, cmd);
}
}

46 changes: 22 additions & 24 deletions src/main/java/com/mycmd/ShellEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,34 @@
import java.io.IOException;
import java.util.Arrays;

/**
* Central execution engine.
*/
/** Central execution engine. */
public class ShellEngine {

private final CommandRegistry registry;
private final ShellContext context;
private final CommandRegistry registry;
private final ShellContext context;

public ShellEngine(CommandRegistry registry, ShellContext context) {
this.registry = registry;
this.context = context;
}
public ShellEngine(CommandRegistry registry, ShellContext context) {
this.registry = registry;
this.context = context;
}

public void execute(String input) {
if (input == null || input.trim().isEmpty()) return;
public void execute(String input) {
if (input == null || input.trim().isEmpty()) return;

String[] parts = input.trim().split("\\s+");
String cmdName = context.resolveAlias(parts[0]);
String[] args = Arrays.copyOfRange(parts, 1, parts.length);
String[] parts = input.trim().split("\\s+");
String cmdName = context.resolveAlias(parts[0]);
String[] args = Arrays.copyOfRange(parts, 1, parts.length);

Command cmd = registry.get(cmdName);
if (cmd == null) {
System.out.println("❌ Unknown command: " + cmdName);
return;
}
Command cmd = registry.get(cmdName);
if (cmd == null) {
System.out.println("❌ Unknown command: " + cmdName);
return;
}

try {
cmd.execute(args, context);
} catch (IOException e) {
System.out.println("⚠️ Error executing command: " + e.getMessage());
}
try {
cmd.execute(args, context);
} catch (IOException e) {
System.out.println("⚠️ Error executing command: " + e.getMessage());
}
}
}
Loading