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 package gov.nist.secauto.metaschema.cli;
28
29 import gov.nist.secauto.metaschema.cli.commands.GenerateSchemaCommand;
30 import gov.nist.secauto.metaschema.cli.commands.ValidateContentUsingModuleCommand;
31 import gov.nist.secauto.metaschema.cli.commands.ValidateModuleCommand;
32 import gov.nist.secauto.metaschema.cli.processor.CLIProcessor;
33 import gov.nist.secauto.metaschema.cli.processor.ExitStatus;
34 import gov.nist.secauto.metaschema.cli.processor.command.CommandService;
35 import gov.nist.secauto.metaschema.core.MetaschemaJavaVersion;
36 import gov.nist.secauto.metaschema.core.model.MetaschemaVersion;
37 import gov.nist.secauto.metaschema.core.util.IVersionInfo;
38 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
39
40 import java.util.List;
41
42 import edu.umd.cs.findbugs.annotations.NonNull;
43
44 @SuppressWarnings("PMD.ShortClassName")
45 public final class CLI {
46 public static void main(String[] args) {
47 System.exit(runCli(args).getExitCode().getStatusCode());
48 }
49
50 @NonNull
51 public static ExitStatus runCli(String... args) {
52 System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");
53
54 List<IVersionInfo> versions = ObjectUtils.notNull(
55 List.of(
56 new MetaschemaJavaVersion(),
57 new MetaschemaVersion()));
58 CLIProcessor processor = new CLIProcessor("metaschema-cli", versions);
59 processor.addCommandHandler(new ValidateModuleCommand());
60 processor.addCommandHandler(new GenerateSchemaCommand());
61 processor.addCommandHandler(new ValidateContentUsingModuleCommand());
62
63 CommandService.getInstance().getCommands().stream().forEach(command -> {
64 assert command != null;
65 processor.addCommandHandler(command);
66 });
67 return processor.process(args);
68 }
69
70 private CLI() {
71
72 }
73 }