MCPcopy Create free account
hub / github.com/apache/solr / main

Method main

solr/core/src/java/org/apache/solr/cli/SolrCLI.java:60–118  ·  view source on GitHub ↗

Runs a tool.

(String[] args)

Source from the content-addressed store, hash-verified

58 private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
59
60 /** Runs a tool. */
61 public static void main(String[] args) throws Exception {
62 ToolRuntime runtime = new DefaultToolRuntime();
63
64 final boolean hasNoCommand =
65 args == null || args.length == 0 || args[0] == null || args[0].trim().isEmpty();
66 final boolean isHelpCommand = !hasNoCommand && Arrays.asList("-h", "--help").contains(args[0]);
67
68 if (hasNoCommand || isHelpCommand) {
69 printHelp();
70 runtime.exit(1);
71 }
72
73 if (Arrays.asList("-v", "--version").contains(args[0])) {
74 // select the version tool to be run, printing the CLIENT version
75 args = new String[] {"version"};
76 }
77 if (Arrays.asList("upconfig", "downconfig", "cp", "rm", "mv", "ls", "mkroot", "updateacls")
78 .contains(args[0])) {
79 // remap our arguments to invoke the zk short tool help
80 args = new String[] {"zk-tool-help", "--print-zk-subcommand-usage", args[0]};
81 }
82 if (Objects.equals(args[0], "zk")) {
83 if (args.length == 1) {
84 // remap our arguments to invoke the ZK tool help.
85 args = new String[] {"zk-tool-help", "--print-long-zk-usage"};
86 } else if (args.length == 2) {
87 if (Arrays.asList("-h", "--help").contains(args[1])) {
88 // remap our arguments to invoke the ZK tool help.
89 args = new String[] {"zk-tool-help", "--print-long-zk-usage"};
90 } else {
91 // remap our arguments to invoke the zk sub command with help
92 String[] trimmedArgs = new String[args.length - 1];
93 System.arraycopy(args, 1, trimmedArgs, 0, trimmedArgs.length);
94 args = trimmedArgs;
95
96 String[] remappedArgs = new String[args.length + 1];
97 System.arraycopy(args, 0, remappedArgs, 0, args.length);
98 remappedArgs[remappedArgs.length - 1] = "--help";
99 args = remappedArgs;
100 }
101 } else {
102 // chop the leading zk argument, so we invoke the correct zk sub tool
103 String[] trimmedArgs = new String[args.length - 1];
104 System.arraycopy(args, 1, trimmedArgs, 0, trimmedArgs.length);
105 args = trimmedArgs;
106 }
107 }
108 SSLConfigurationsFactory.current().init();
109
110 Tool tool = null;
111 try {
112 tool = findTool(args, runtime);
113 } catch (IllegalArgumentException iae) {
114 CLIO.err(iae.getMessage());
115 runtime.exit(1);
116 }
117 CommandLine cli = parseCmdLine(tool, args);

Callers

nothing calls this directly

Calls 14

printHelpMethod · 0.95
currentMethod · 0.95
findToolMethod · 0.95
errMethod · 0.95
parseCmdLineMethod · 0.95
runToolMethod · 0.95
initMethod · 0.65
isEmptyMethod · 0.45
trimMethod · 0.45
containsMethod · 0.45
asListMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected