Command-line utility for working with Solr.
| 53 | import org.slf4j.LoggerFactory; |
| 54 | |
| 55 | /** Command-line utility for working with Solr. */ |
| 56 | public class SolrCLI implements CLIO { |
| 57 | |
| 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); |
nothing calls this directly
no test coverage detected
searching dependent graphs…