3 changed files with 83 additions and 0 deletions
@ -0,0 +1,19 @@ |
|||||
|
package com.crawler.command; |
||||
|
|
||||
|
public class ExitCommand extends BaseCommand { |
||||
|
@Override |
||||
|
public String getName() { |
||||
|
return "exit"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getDescription() { |
||||
|
return "退出程序"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void execute() { |
||||
|
System.out.println("退出程序..."); |
||||
|
System.exit(0); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
package com.crawler.command; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public class HelpCommand extends BaseCommand { |
||||
|
private List<Command> commands; |
||||
|
|
||||
|
public HelpCommand(List<Command> commands) { |
||||
|
this.commands = commands; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getName() { |
||||
|
return "help"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getDescription() { |
||||
|
return "显示所有可用指令"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void execute() { |
||||
|
System.out.println("可用指令:"); |
||||
|
System.out.println("---------"); |
||||
|
for (Command cmd : commands) { |
||||
|
System.out.printf("%-8s : %s%n", cmd.getName(), cmd.getDescription()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
package com.crawler.command; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public class ListCommand extends BaseCommand { |
||||
|
@Override |
||||
|
public String getName() { |
||||
|
return "list"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getDescription() { |
||||
|
return "查看使用过的指令历史"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void execute() { |
||||
|
List<String> historyList = history.getHistory(); |
||||
|
|
||||
|
System.out.println("========================================"); |
||||
|
System.out.println("指令历史记录:"); |
||||
|
System.out.println("========================================"); |
||||
|
|
||||
|
if (historyList.isEmpty()) { |
||||
|
System.out.println("暂无指令记录"); |
||||
|
} else { |
||||
|
for (int i = 0; i < historyList.size(); i++) { |
||||
|
System.out.printf("[%d] %s%n", i + 1, historyList.get(i)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
System.out.println("========================================"); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue