blob: 8fa77c2bbe6c001a1420ff40b520f3a2843eecca (
plain)
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
|
package market.guess.ui.console.command;
import market.guess.api.CatalogContext;
import market.guess.ui.console.io.InputProcessor;
public final class LoadMarketStateMenuCommand implements MenuCommand {
private final CatalogContext catalog;
private final InputProcessor io;
public LoadMarketStateMenuCommand(CatalogContext catalog, InputProcessor io) {
super();
this.catalog = catalog;
this.io = io;
}
@Override
public int getIndex() {
return 8;
}
@Override
public String getName() {
return "Load market state";
}
@Override
public void execute() {
var path = io.readPath("Please enter full path to state file (without or with .json extension): ");
var result = catalog.restoreState(path);
if (result.isSuccess()) {
io.println("Successfully restored %d event(s) from %s.".formatted(result.getData().eventsLoaded(), path));
} else {
var msg =
result.getDetails() != null && !result.getDetails().isBlank()
? result.getDetails()
: result.getMessage();
io.println("Failed to restore state: %s".formatted(msg));
}
}
}
|