Skip to content

Commit d9ef9fa

Browse files
Merge pull request #80 from nihaltp/des
update description & usage
2 parents 0566638 + 1b0106b commit d9ef9fa

19 files changed

+167
-15
lines changed

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
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class MkdirCommand implements Command {
2020
@Override
2121
public void execute(String[] args, ShellContext context) {
2222
if (args.length == 0) {
23-
System.out.println("Usage: mkdir <directory_name>");
23+
System.out.println("Usage: " + usage());
2424
return;
2525
}
2626
File dir = new File(context.getCurrentDir(), args[0]);
@@ -32,4 +32,14 @@ public void execute(String[] args, ShellContext context) {
3232
System.out.println("Failed to create directory.");
3333
}
3434
}
35+
36+
@Override
37+
public String description() {
38+
return "Create a new directory.";
39+
}
40+
41+
@Override
42+
public String usage() {
43+
return "mkdir <directory_name>";
44+
}
3545
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class MoveCommand implements Command {
2323
@Override
2424
public void execute(String[] args, ShellContext context) throws IOException {
2525
if (args.length < 2) {
26-
System.out.println("Usage: move <source> <destination>");
26+
System.out.println("Usage: " + usage());
2727
return;
2828
}
2929

0 commit comments

Comments
 (0)