Skip to content

Commit 86658e3

Browse files
author
studentpiyush
committed
Resolved merge conflicts in HelpCommand.java
1 parent e808676 commit 86658e3

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
* Enhanced HelpCommand
99
* --------------------
1010
* Dynamically lists all available commands with their descriptions.
11-
*
12-
* Features:
13-
* - Automatically updates when new commands are added to the registry.
14-
* - Displays both command names and short descriptions.
15-
* - Supports optional usage help: "help <command>".
11+
* Supports detailed help for individual commands using 'help <command>'.
1612
*/
1713
public class HelpCommand implements Command {
1814
private final Map<String, Command> commands;
@@ -23,38 +19,31 @@ public HelpCommand(Map<String, Command> commands) {
2319

2420
@Override
2521
public void execute(String[] args, ShellContext context) {
26-
// Case 1: user asked for detailed help about one command
22+
// Detailed help for a specific command
2723
if (args.length > 1) {
2824
String cmdName = args[1];
2925
Command cmd = commands.get(cmdName);
3026

3127
if (cmd != null) {
3228
System.out.println("\nCommand: " + cmdName);
3329
System.out.println("Description: " + cmd.description());
34-
if (cmd.usage() != null && !cmd.usage().isEmpty()) {
35-
System.out.println("Usage: " + cmd.usage());
36-
} else {
37-
System.out.println("Usage: " + cmdName + " [options]");
38-
}
30+
System.out.println("Usage: " + (cmd.usage() != null ? cmd.usage() : cmdName + " [options]"));
3931
} else {
4032
System.out.println("No such command: " + cmdName);
4133
}
4234
return;
4335
}
4436

45-
// Case 2: user just typed 'help'
37+
// General help listing all commands
4638
System.out.println("\nMyCMD — Available Commands:\n");
4739
for (Map.Entry<String, Command> entry : commands.entrySet()) {
4840
String name = entry.getKey();
4941
Command cmd = entry.getValue();
50-
5142
String description = (cmd.description() != null && !cmd.description().isEmpty())
5243
? cmd.description()
5344
: "No description available";
54-
5545
System.out.printf(" %-12s : %s%n", name, description);
5646
}
57-
5847
System.out.println("\nType 'help <command>' for detailed info about a specific command.\n");
5948
}
6049

0 commit comments

Comments
 (0)