Skip to content

Commit ee29e87

Browse files
Apply Spotless formatting
1 parent 5b02149 commit ee29e87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1068
-1099
lines changed

src/main/java/com/mycmd/App.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.mycmd;
22

33
import com.mycmd.commands.*;
4-
54
import java.util.*;
65
import java.util.Scanner;
76

@@ -41,7 +40,12 @@ public static void main(String[] args) {
4140
}
4241
} else {
4342
// Single, clear not-recognized message + optional suggestion
44-
System.out.println("Unknown command: '" + cmd + "'. Enter '" + CommandNames.HELP + "' to list all available commands.");
43+
System.out.println(
44+
"Unknown command: '"
45+
+ cmd
46+
+ "'. Enter '"
47+
+ CommandNames.HELP
48+
+ "' to list all available commands.");
4549

4650
// compute suggestion safely
4751
try {
@@ -74,6 +78,7 @@ private static String resolveAliases(String input, ShellContext context) {
7478

7579
private static final class CommandNames {
7680
private CommandNames() {}
81+
7782
private static final String ALIAS = "alias";
7883
private static final String ARP = "arp";
7984
private static final String ASSOC = "assoc";
@@ -86,7 +91,7 @@ private CommandNames() {}
8691
private static final String CLS = "cls";
8792
private static final String COLOR = "color";
8893
private static final String COMPACT = "compact";
89-
private static final String COPY = "copy";
94+
private static final String COPY = "copy";
9095
private static final String DATE = "date";
9196
private static final String DEL = "del";
9297
private static final String DIR = "dir";
@@ -115,7 +120,7 @@ private CommandNames() {}
115120
private static final String NETSTAT = "netstat";
116121
private static final String NSLOOKUP = "nslookup";
117122
private static final String PATH = "path";
118-
private static final String PAUSE = "pause";
123+
private static final String PAUSE = "pause";
119124
private static final String PING = "ping";
120125
private static final String PWD = "pwd";
121126
private static final String REM = "rem";
@@ -149,7 +154,7 @@ private CommandNames() {}
149154
private static final String WMIC = "wmic";
150155
private static final String XCOPY = "xcopy";
151156
}
152-
157+
153158
private static void registerCommands(Map<String, Command> commands) {
154159
commands.put(CommandNames.ALIAS, new AliasCommand());
155160
commands.put(CommandNames.ARP, new ArpCommand());
@@ -206,7 +211,7 @@ private static void registerCommands(Map<String, Command> commands) {
206211
commands.put(CommandNames.SHUTDOWN, new ShutdownCommand());
207212
commands.put(CommandNames.SORT, new SortCommand());
208213
commands.put(CommandNames.START, new StartCommand());
209-
commands.put(CommandNames.SYSTEMINFO, new SysteminfoCommand());
214+
commands.put(CommandNames.SYSTEMINFO, new SysteminfoCommand());
210215
commands.put(CommandNames.TASKKILL, new TaskkillCommand());
211216
commands.put(CommandNames.TASKLIST, new TasklistCommand());
212217
commands.put(CommandNames.TELNET, new TelnetCommand());

src/main/java/com/mycmd/Command.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import java.io.IOException;
44

55
/**
6-
* Represents a shell command that can be executed inside the MyCMD shell.
7-
* Implementations perform their operation when {@link #execute(String[], ShellContext)} is called.
6+
* Represents a shell command that can be executed inside the MyCMD shell. Implementations perform
7+
* their operation when {@link #execute(String[], ShellContext)} is called.
88
*/
99
public interface Command {
1010
/**
1111
* Execute the command.
1212
*
13-
* @param args command-line style arguments passed to the command. May be empty but will not be null.
13+
* @param args command-line style arguments passed to the command. May be empty but will not be
14+
* null.
1415
* @param context current shell context containing state such as the current working directory.
1516
* @throws IOException if the command cannot complete successfully.
1617
*/
@@ -23,10 +24,8 @@ default String description() {
2324
return "";
2425
}
2526

26-
/**
27-
* Usage string for the command. Default is empty.
28-
*/
27+
/** Usage string for the command. Default is empty. */
2928
default String usage() {
3029
return "";
3130
}
32-
}
31+
}

src/main/java/com/mycmd/ShellContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.mycmd;
22

33
import java.io.*;
4-
import java.util.*;
54
import java.time.Instant;
5+
import java.util.*;
66

77
public class ShellContext {
88
private File currentDir;
@@ -116,8 +116,9 @@ private void saveAliases() {
116116
}
117117

118118
/**
119-
* Resolve the given path (absolute or relative) to a File using the current directory.
120-
* If the provided path is absolute, returns it directly; otherwise returns a File rooted at currentDir.
119+
* Resolve the given path (absolute or relative) to a File using the current directory. If the
120+
* provided path is absolute, returns it directly; otherwise returns a File rooted at
121+
* currentDir.
121122
*/
122123
public File resolvePath(String path) {
123124
if (path == null || path.trim().isEmpty()) {
@@ -147,5 +148,4 @@ public String getEnvVar(String key) {
147148
public Map<String, String> getEnvVars() {
148149
return new HashMap<>(envVars);
149150
}
150-
151151
}

src/main/java/com/mycmd/StringUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import java.util.Objects;
55

66
/**
7-
* Small utility for string-based helper methods.
8-
* Provides a findClosest(...) implementation using Levenshtein distance.
7+
* Small utility for string-based helper methods. Provides a findClosest(...) implementation using
8+
* Levenshtein distance.
99
*/
1010
public final class StringUtils {
1111

1212
private StringUtils() {}
1313

1414
/**
15-
* Find the closest string in candidates to the input.
16-
* Returns null when no candidate is close enough.
15+
* Find the closest string in candidates to the input. Returns null when no candidate is close
16+
* enough.
1717
*
1818
* @param input the input string
1919
* @param candidates candidate strings
@@ -85,4 +85,4 @@ private static int levenshteinDistance(String a, String b) {
8585
private static int min3(int x, int y, int z) {
8686
return Math.min(x, Math.min(y, z));
8787
}
88-
}
88+
}

src/main/java/com/mycmd/commands/AliasCommand.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.mycmd.Command;
44
import com.mycmd.ShellContext;
5-
65
import java.io.IOException;
76
import java.util.Map;
87

@@ -62,8 +61,8 @@ public String description() {
6261

6362
@Override
6463
public String usage() {
65-
return "alias # list aliases\n" +
66-
"alias name=command # create alias\n" +
67-
"alias name command... # create alias";
64+
return "alias # list aliases\n"
65+
+ "alias name=command # create alias\n"
66+
+ "alias name command... # create alias";
6867
}
69-
}
68+
}

src/main/java/com/mycmd/commands/ArpCommand.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,66 @@
22

33
import com.mycmd.Command;
44
import com.mycmd.ShellContext;
5-
65
import java.io.BufferedReader;
76
import java.io.IOException;
87
import java.io.InputStreamReader;
98

109
/**
1110
* Displays and modifies the IP-to-Physical address translation tables (ARP cache).
12-
*
13-
* Usage:
14-
* - arp -a : Display ARP cache
11+
*
12+
* <p>Usage: - arp -a : Display ARP cache
1513
*/
1614
public class ArpCommand implements Command {
17-
15+
1816
@Override
1917
public void execute(String[] args, ShellContext context) throws IOException {
2018
try {
2119
StringBuilder cmdBuilder = new StringBuilder("arp");
2220
for (String arg : args) {
2321
cmdBuilder.append(" ").append(arg);
2422
}
25-
23+
2624
// Default to -a if no args provided
2725
if (args.length == 0) {
2826
cmdBuilder.append(" -a");
2927
}
30-
28+
3129
ProcessBuilder pb = new ProcessBuilder();
3230
String os = System.getProperty("os.name").toLowerCase();
33-
31+
3432
if (os.contains("win")) {
3533
pb.command("cmd.exe", "/c", cmdBuilder.toString());
3634
} else {
3735
pb.command("sh", "-c", cmdBuilder.toString());
3836
}
39-
37+
4038
Process process = pb.start();
41-
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
42-
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
43-
39+
BufferedReader reader =
40+
new BufferedReader(new InputStreamReader(process.getInputStream()));
41+
BufferedReader errorReader =
42+
new BufferedReader(new InputStreamReader(process.getErrorStream()));
43+
4444
String line;
4545
while ((line = reader.readLine()) != null) {
4646
System.out.println(line);
4747
}
48-
48+
4949
while ((line = errorReader.readLine()) != null) {
5050
System.err.println(line);
5151
}
52-
52+
5353
process.waitFor();
54-
54+
5555
} catch (Exception e) {
5656
System.out.println("Error executing arp: " + e.getMessage());
5757
}
5858
}
59-
59+
6060
@Override
6161
public String description() {
6262
return "Displays and modifies the IP-to-Physical address translation tables.";
6363
}
64-
64+
6565
@Override
6666
public String usage() {
6767
return "arp [-a] [-d ip_addr] [-s ip_addr eth_addr]";

src/main/java/com/mycmd/commands/AssocCommand.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,53 @@
22

33
import com.mycmd.Command;
44
import com.mycmd.ShellContext;
5-
65
import java.io.BufferedReader;
76
import java.io.IOException;
87
import java.io.InputStreamReader;
98

109
/**
1110
* Displays or modifies file extension associations.
12-
*
13-
* Usage:
14-
* - assoc : Display all associations
15-
* - assoc .ext : Display association for extension
11+
*
12+
* <p>Usage: - assoc : Display all associations - assoc .ext : Display association for extension
1613
*/
1714
public class AssocCommand implements Command {
18-
15+
1916
@Override
2017
public void execute(String[] args, ShellContext context) throws IOException {
2118
String os = System.getProperty("os.name").toLowerCase();
22-
19+
2320
if (!os.contains("win")) {
2421
System.out.println("ASSOC is only available on Windows systems.");
2522
return;
2623
}
27-
24+
2825
try {
2926
StringBuilder cmdBuilder = new StringBuilder("assoc");
3027
for (String arg : args) {
3128
cmdBuilder.append(" ").append(arg);
3229
}
33-
30+
3431
Process process = Runtime.getRuntime().exec(cmdBuilder.toString());
35-
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
36-
32+
BufferedReader reader =
33+
new BufferedReader(new InputStreamReader(process.getInputStream()));
34+
3735
String line;
3836
while ((line = reader.readLine()) != null) {
3937
System.out.println(line);
4038
}
41-
39+
4240
process.waitFor();
43-
41+
4442
} catch (Exception e) {
4543
System.out.println("Error executing assoc: " + e.getMessage());
4644
}
4745
}
48-
46+
4947
@Override
5048
public String description() {
5149
return "Displays or modifies file extension associations.";
5250
}
53-
51+
5452
@Override
5553
public String usage() {
5654
return "assoc [.ext[=[fileType]]]";

0 commit comments

Comments
 (0)