-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeCommandRunner.java
More file actions
44 lines (35 loc) · 1.31 KB
/
NodeCommandRunner.java
File metadata and controls
44 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@Component
public class NodeCommandRunner implements CommandLineRunner {
private final PeerGrpcService peerService;
private final ClientService clientService;
public NodeCommandRunner(PeerGrpcService peerService, ClientService clientService) {
this.peerService = peerService;
this.clientService = clientService;
}
@Override
public void run(String... args) throws Exception {
Scanner scanner = new Scanner(System.in);
System.out.println("Commands:");
System.out.println(" upload <path>");
System.out.println(" download <filename>");
System.out.println(" exit");
while (true) {
System.out.print("> ");
String line = scanner.nextLine().trim();
if (line.equals("exit")) {
break;
}
if (line.startsWith("upload ")) {
String path = line.substring("upload ".length()).trim();
//use peer service to share file
continue;
}
if (line.startsWith("download ")) {
String filename = line.substring("download ".length()).trim();
//use client service to download file
continue;
}
System.out.println("Unknown command.");
}
}
}