/
TrueNasCommand.java
57 lines (45 loc) · 1.83 KB
/
TrueNasCommand.java
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
45
46
47
48
49
50
51
52
53
54
55
56
57
package dev.oaiqiy.truenas.scale.sdk.common;
import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import static dev.oaiqiy.truenas.scale.sdk.exception.TrueNasException.exception;
import static dev.oaiqiy.truenas.scale.sdk.exception.TrueNasExceptionErrorCode.NO_SUCH_SERVICE;
@AllArgsConstructor
@Getter
public enum TrueNasCommand {
SYSTEM_SHUTDOWN("system shutdown", "shutdown"),
CHART_RELEASE("chart release query", "app query"),
CHART_RELEASE_LIST("chart release list", "app list"),
CHART_RELEASE_POD_STATUS("char release pod status", "app status"),
CHART_RELEASE_SCALE("chart release scale", "app scale"),
CHART_RELEASE_START("chart release start", "app start"),
CHART_RELEASE_STOP("chart release stop", "app stop"),
CHART_RELEASE_RESTART("chart release restart", "app restart"),
POOL_DATASET_UNLOCK("pool dataset unlock", "unlock"),
POOL_DATASET("pool dataset query", null),
;
private static final Map<String, TrueNasCommand> duplicate = Maps.newHashMap();
static {
Arrays.stream(values()).forEach(command -> {
if (duplicate.containsKey(command.getCommand())) {
throw new RuntimeException();
}
if (Objects.nonNull(command.getAlias()) && duplicate.containsKey(command.getAlias())) {
throw new RuntimeException();
}
duplicate.put(command.getCommand(), command);
duplicate.put(command.getAlias(), command);
});
}
private final String command;
private final String alias;
public static TrueNasCommand parse(String s) {
if (!duplicate.containsKey(s)) {
throw exception(NO_SUCH_SERVICE);
}
return duplicate.get(s);
}
}