-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathValidateCommand.java
More file actions
45 lines (38 loc) · 1.68 KB
/
ValidateCommand.java
File metadata and controls
45 lines (38 loc) · 1.68 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
45
package com.devshawn.kafka.gitops.cli;
import com.devshawn.kafka.gitops.MainCommand;
import com.devshawn.kafka.gitops.StateManager;
import com.devshawn.kafka.gitops.config.ManagerConfig;
import com.devshawn.kafka.gitops.exception.ValidationException;
import com.devshawn.kafka.gitops.service.ParserService;
import com.devshawn.kafka.gitops.util.LogUtil;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import java.util.concurrent.Callable;
@Command(name = "validate", description = "Validates the desired state file.")
public class ValidateCommand implements Callable<Integer> {
@CommandLine.ParentCommand
private MainCommand parent;
@Override
public Integer call() {
try {
ParserService parserService = new ParserService(parent.getStateFile());
StateManager stateManager = new StateManager(generateStateManagerConfig(), parserService);
stateManager.getAndValidateStateFile();
LogUtil.printValidationResult("Successfully validated the desired state file.", true);
return 0;
} catch (ValidationException ex) {
LogUtil.printValidationResult(ex.getMessage(), false);
}
return 2;
}
private ManagerConfig generateStateManagerConfig() {
return new ManagerConfig.Builder()
.setVerboseRequested(parent.isVerboseRequested())
.setDeleteDisabled(parent.isDeleteDisabled())
.setIncludeUnchangedEnabled(false)
.setSkipAclsDisabled(parent.areAclsDisabled())
.setNullableConfigFile(parent.getConfigFile())
.setStateFile(parent.getStateFile())
.build();
}
}