Skip to content

Commit ffa2d92

Browse files
authored
Merge branch 'Drive-for-Java:main' into feat/add-lombok
2 parents a045da7 + 0f5fb4f commit ffa2d92

23 files changed

+353
-54
lines changed

CheckList.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
---
88

99
## 🧭 System Information & Management
10-
- [ ] systeminfo
10+
- [x] systeminfo
1111
- [x] hostname
1212
- [x] ver
1313
- [ ] vol
@@ -108,7 +108,7 @@
108108

109109
## ⚙️ Automation & Scripting
110110
- [x] echo
111-
- [ ] pause
111+
- [x] pause
112112
- [x] cls
113113
- [x] exit
114114
- [x] title
@@ -188,7 +188,7 @@
188188
- [x] md / mkdir
189189
- [x] move
190190
- [ ] path
191-
- [ ] pause
191+
- [x] pause
192192
- [ ] popd
193193
- [ ] prompt
194194
- [ ] pushd

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

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void main(String[] args) {
4242
}
4343
} else {
4444
// Single, clear not-recognized message + optional suggestion
45-
System.out.println("Unknown command: '" + cmd + "'. Enter 'help' to list all available commands.");
45+
System.out.println("Unknown command: '" + cmd + "'. Enter '" + CommandNames.HELP + "' to list all available commands.");
4646

4747
// compute suggestion safely
4848
try {
@@ -73,40 +73,78 @@ private static String resolveAliases(String input, ShellContext context) {
7373
return input;
7474
}
7575

76+
private static final class CommandNames {
77+
private CommandNames() {}
78+
private static final String ALIAS = "alias";
79+
private static final String CD = "cd";
80+
private static final String CLEARHISTORY = "clearhistory";
81+
private static final String CLS = "cls";
82+
private static final String COLOR = "color";
83+
private static final String COPY = "copy";
84+
private static final String DATE = "date";
85+
private static final String DEL = "del";
86+
private static final String DIR = "dir";
87+
private static final String ECHO = "echo";
88+
private static final String EXIT = "exit";
89+
private static final String HELP = "help";
90+
private static final String HISTORY = "history";
91+
private static final String HOSTNAME = "hostname";
92+
private static final String IPCONFIG = "ipconfig";
93+
private static final String MKDIR = "mkdir";
94+
private static final String PAUSE = "pause";
95+
private static final String PING = "ping";
96+
private static final String PWD = "pwd";
97+
private static final String RENAME = "rename";
98+
private static final String RMDIR = "rmdir";
99+
private static final String SET = "set";
100+
private static final String SYSTEMINFO = "systeminfo";
101+
private static final String TASKLIST = "tasklist";
102+
private static final String TELNET = "telnet";
103+
private static final String TIME = "time";
104+
private static final String TITLE = "title";
105+
private static final String TOUCH = "touch";
106+
private static final String TREE = "tree";
107+
private static final String TYPE = "type";
108+
private static final String UNALIAS = "unalias";
109+
private static final String UPTIME = "uptime";
110+
private static final String VER = "ver";
111+
private static final String WHOAMI = "whoami";
112+
}
113+
76114
private static void registerCommands(Map<String, Command> commands) {
77-
commands.put("dir", new DirCommand());
78-
commands.put("cd", new CdCommand());
79-
commands.put("echo", new EchoCommand());
80-
commands.put("mkdir", new MkdirCommand());
81-
commands.put("rmdir", new RmdirCommand());
82-
commands.put("copy", new CopyCommand());
83-
commands.put("del", new DelCommand());
84-
commands.put("type", new TypeCommand());
85-
commands.put("cls", new ClsCommand());
86-
commands.put("help", new HelpCommand(commands));
87-
commands.put("exit", new ExitCommand());
88-
commands.put("ver", new VersionCommand());
89-
commands.put("title", new TitleCommand());
90-
commands.put("color", new ColorCommand());
91-
commands.put("hostname", new HostnameCommand());
92-
commands.put("whoami", new WhoamiCommand());
93-
commands.put("touch", new TouchCommand());
94-
commands.put("time", new TimeCommand());
95-
commands.put("tasklist", new TasklistCommand());
96-
commands.put("tree", new TreeCommand());
97-
commands.put("date", new DateCommand());
98-
commands.put("history", new HistoryCommand());
99-
commands.put("ping", new PingCommand());
100-
commands.put("telnet", new TelnetCommand());
101-
commands.put("pwd", new PwdCommand());
102-
commands.put("uptime", new UptimeCommand());
103-
commands.put("clearhistory", new ClearHistoryCommand());
104-
commands.put("ipconfig", new IpConfig());
105-
commands.put("alias", new AliasCommand());
106-
commands.put("unalias", new UnaliasCommand());
107-
commands.put("rename", new RenameCommand());
108-
commands.put("set", new SetCommand());
109-
}
115+
commands.put(CommandNames.ALIAS, new AliasCommand());
116+
commands.put(CommandNames.CD, new CdCommand());
117+
commands.put(CommandNames.CLEARHISTORY, new ClearHistoryCommand());
118+
commands.put(CommandNames.CLS, new ClsCommand());
119+
commands.put(CommandNames.COLOR, new ColorCommand());
120+
commands.put(CommandNames.COPY, new CopyCommand());
121+
commands.put(CommandNames.DATE, new DateCommand());
122+
commands.put(CommandNames.DEL, new DelCommand());
123+
commands.put(CommandNames.DIR, new DirCommand());
124+
commands.put(CommandNames.ECHO, new EchoCommand());
125+
commands.put(CommandNames.EXIT, new ExitCommand());
126+
commands.put(CommandNames.HELP, new HelpCommand(commands));
127+
commands.put(CommandNames.HISTORY, new HistoryCommand());
128+
commands.put(CommandNames.HOSTNAME, new HostnameCommand());
129+
commands.put(CommandNames.IPCONFIG, new IpConfig());
130+
commands.put(CommandNames.MKDIR, new MkdirCommand());
131+
commands.put(CommandNames.PAUSE, new PauseCommand());
132+
commands.put(CommandNames.PING, new PingCommand());
133+
commands.put(CommandNames.PWD, new PwdCommand());
134+
commands.put(CommandNames.RENAME, new RenameCommand());
135+
commands.put(CommandNames.RMDIR, new RmdirCommand());
136+
commands.put(CommandNames.SET, new SetCommand());
137+
commands.put(CommandNames.SYSTEMINFO, new SysteminfoCommand());
138+
commands.put(CommandNames.TASKLIST, new TasklistCommand());
139+
commands.put(CommandNames.TELNET, new TelnetCommand());
140+
commands.put(CommandNames.TIME, new TimeCommand());
141+
commands.put(CommandNames.TITLE, new TitleCommand());
142+
commands.put(CommandNames.TOUCH, new TouchCommand());
143+
commands.put(CommandNames.TREE, new TreeCommand());
144+
commands.put(CommandNames.TYPE, new TypeCommand());
145+
commands.put(CommandNames.UNALIAS, new UnaliasCommand());
146+
commands.put(CommandNames.UPTIME, new UptimeCommand());
147+
commands.put(CommandNames.VER, new VersionCommand());
148+
commands.put(CommandNames.WHOAMI, new WhoamiCommand());
149+
}
110150
}
111-
112-

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void execute(String[] args, ShellContext context) throws IOException {
2626
String name = parts[0].trim();
2727
String cmd = parts[1].trim();
2828
if (name.isEmpty() || cmd.isEmpty()) {
29-
System.out.println("Invalid alias format. Usage: alias name=command");
29+
System.out.println("Invalid alias format. Usage: \n" + usage());
3030
return;
3131
}
3232
context.addAlias(name, cmd);
@@ -44,15 +44,15 @@ public void execute(String[] args, ShellContext context) throws IOException {
4444
}
4545
String cmd = sb.toString();
4646
if (name.trim().isEmpty() || cmd.trim().isEmpty()) {
47-
System.out.println("Invalid alias. Usage: alias name command... or alias name=command");
47+
System.out.println("Invalid alias. Usage: \n" + usage());
4848
return;
4949
}
5050
context.addAlias(name, cmd);
5151
System.out.println("Alias added: " + name + "=" + cmd);
5252
return;
5353
}
5454

55-
System.out.println("Invalid usage. Usage: alias [name=command] | alias [name command...]");
55+
System.out.println("Invalid usage. Usage: " + usage());
5656
}
5757

5858
@Override

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,14 @@ public void execute(String[] args, ShellContext context) {
5353
System.out.println("The system cannot find the path specified.");
5454
}
5555
}
56+
57+
@Override
58+
public String description() {
59+
return "Change the current working directory or display it.";
60+
}
61+
62+
@Override
63+
public String usage() {
64+
return "cd [path]";
65+
}
5666
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,14 @@ public void execute(String[] args, ShellContext context) {
3434
System.out.println("Error while clearing the screen: " + e.getMessage());
3535
}
3636
}
37+
38+
@Override
39+
public String description() {
40+
return "Clear the console screen.";
41+
}
42+
43+
@Override
44+
public String usage() {
45+
return "cls";
46+
}
3747
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void execute(String[] args, ShellContext context) {
2626
String color = args[0];
2727

2828
if (color.length() != 2) {
29-
System.out.println("Usage: color <background><text>");
29+
System.out.println("Usage: " + usage());
3030
return;
3131
}
3232

@@ -67,4 +67,17 @@ public void execute(String[] args, ShellContext context) {
6767
System.out.println("\033[0m");
6868
}
6969
}
70+
71+
@Override
72+
public String description() {
73+
return "Change console text and background colors.";
74+
}
75+
76+
@Override
77+
public String usage() {
78+
return "color [<background><text>]\n" +
79+
" <background> and <text> are hexadecimal digits (0-9, A-F).\n" +
80+
" Example: color 0A sets black background with bright green text.\n" +
81+
" Call without arguments to reset to default colors.";
82+
}
7083
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class CopyCommand implements Command {
2222
@Override
2323
public void execute(String[] args, ShellContext context) {
2424
if (args.length < 2) {
25-
System.out.println("Usage: copy <source> <destination>");
25+
System.out.println("Usage: " + usage());
2626
return;
2727
}
2828
File src = new File(context.getCurrentDir(), args[0]);
@@ -43,4 +43,14 @@ public void execute(String[] args, ShellContext context) {
4343
System.out.println("Error copying file: " + e.getMessage());
4444
}
4545
}
46+
47+
@Override
48+
public String description() {
49+
return "Copy a file from source to destination.";
50+
}
51+
52+
@Override
53+
public String usage() {
54+
return "copy <source> <destination>";
55+
}
4656
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class DelCommand implements Command {
2121
@Override
2222
public void execute(String[] args, ShellContext context) {
2323
if (args.length == 0) {
24-
System.out.println("Usage: del <file_name>");
24+
System.out.println("Usage: " + usage());
2525
return;
2626
}
2727
for (String name : args) {
@@ -35,4 +35,14 @@ public void execute(String[] args, ShellContext context) {
3535
}
3636
}
3737
}
38+
39+
@Override
40+
public String description() {
41+
return "Delete one or more files.";
42+
}
43+
44+
@Override
45+
public String usage() {
46+
return "del <file1> [file2 ...]";
47+
}
3848
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ public void execute(String[] args, ShellContext context) {
2020
System.out.println((i + 1) + ". " + history.get(i));
2121
}
2222
}
23+
24+
@Override
25+
public String description() {
26+
return "Display the list of previously executed commands.";
27+
}
28+
29+
@Override
30+
public String usage() {
31+
return "history";
32+
}
2333
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,14 @@ public void execute(String[] args, ShellContext context) {
3131
}
3232
System.out.println(hostname);
3333
}
34+
35+
@Override
36+
public String description() {
37+
return "Display the hostname of the current computer.";
38+
}
39+
40+
@Override
41+
public String usage() {
42+
return "hostname";
43+
}
3444
}

0 commit comments

Comments
 (0)