|
|
@ -1,13 +1,17 @@ |
|
|
package internal.hw.crawler.commands; |
|
|
package internal.hw.crawler.commands; |
|
|
|
|
|
|
|
|
|
|
|
import internal.hw.crawler.views.CommandOutput; |
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
public class HelpCommand implements Command { |
|
|
public class HelpCommand implements Command { |
|
|
private final Map<String, Command> commands; |
|
|
private final Map<String, Command> commands; |
|
|
|
|
|
private final CommandOutput out; |
|
|
|
|
|
|
|
|
public HelpCommand(Map<String, Command> commands) { |
|
|
public HelpCommand(Map<String, Command> commands, CommandOutput out) { |
|
|
this.commands = commands; |
|
|
this.commands = commands; |
|
|
|
|
|
this.out = out; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@ -32,34 +36,33 @@ public class HelpCommand implements Command { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void showAll() { |
|
|
private void showAll() { |
|
|
System.out.println("Available commands:"); |
|
|
out.info("Available commands:"); |
|
|
for (Command cmd : commands.values()) { |
|
|
for (Command cmd : commands.values()) { |
|
|
System.out.printf(" %s", cmd.getName()); |
|
|
out.print(" " + cmd.getName()); |
|
|
System.out.println(); |
|
|
|
|
|
} |
|
|
} |
|
|
System.out.println("Type `help <command>` to show detailed help for a specific command."); |
|
|
out.info("Type `help <command>` to show detailed help for a specific command."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void showDetail(String name) { |
|
|
private void showDetail(String name) { |
|
|
Command cmd = commands.get(name); |
|
|
Command cmd = commands.get(name); |
|
|
if (cmd == null) { |
|
|
if (cmd == null) { |
|
|
System.out.println("Unknown command: " + name); |
|
|
out.error("Unknown command: " + name); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
System.out.println("Command: " + cmd.getName()); |
|
|
out.info("Command: " + cmd.getName()); |
|
|
List<CommandArg> cmdArgs = cmd.getArgs(); |
|
|
List<CommandArg> cmdArgs = cmd.getArgs(); |
|
|
if (cmdArgs.isEmpty()) { |
|
|
if (cmdArgs.isEmpty()) { |
|
|
System.out.println(" No arguments."); |
|
|
out.print(" No arguments."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
System.out.println("Arguments:"); |
|
|
out.info("Arguments:"); |
|
|
for (CommandArg arg : cmdArgs) { |
|
|
for (CommandArg arg : cmdArgs) { |
|
|
System.out.printf(" %s %s %s%n", |
|
|
out.print(String.format(" %s %s %s", |
|
|
arg.required() ? "[R]" : " ", |
|
|
arg.required() ? "[Required]" : " ", |
|
|
arg.name(), |
|
|
arg.name(), |
|
|
arg.description()); |
|
|
arg.description())); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|