blob: 78a5ca0a9335b6f65953279ba763dbbbd04aff6c (
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 SaveMarketStateMenuCommand implements MenuCommand {
private final CatalogContext catalog;
private final InputProcessor io;
public SaveMarketStateMenuCommand(CatalogContext catalog, InputProcessor io) {
super();
this.catalog = catalog;
this.io = io;
}
@Override
public int getIndex() {
return 7;
}
@Override
public String getName() {
return "Save current state";
}
@Override
public void execute() {
var path = io.readPath("Please enter full path to save file (without or with .json extension): ");
var result = catalog.saveState(path);
if (result.isSuccess()) {
io.println("Successfully saved current market state to %s.".formatted(path));
} else {
var msg =
result.getDetails() != null && !result.getDetails().isBlank()
? result.getDetails()
: result.getMessage();
io.println("Failed to save state: %s".formatted(msg));
}
}
}
|