| 25 | import org.apache.solr.util.StartupLoggingUtils; |
| 26 | |
| 27 | public abstract class ToolBase implements Tool { |
| 28 | |
| 29 | protected final ToolRuntime runtime; |
| 30 | |
| 31 | private boolean verbose = false; |
| 32 | |
| 33 | protected ToolBase(ToolRuntime runtime) { |
| 34 | this.runtime = runtime; |
| 35 | } |
| 36 | |
| 37 | /** Is this tool being run in a verbose mode? */ |
| 38 | protected boolean isVerbose() { |
| 39 | return verbose; |
| 40 | } |
| 41 | |
| 42 | protected void echoIfVerbose(final String msg) { |
| 43 | if (verbose) { |
| 44 | echo(msg); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | protected void echoIfVerbose(Object response) throws JsonProcessingException { |
| 49 | if (verbose && response != null) { |
| 50 | echo( |
| 51 | JacksonContentWriter.DEFAULT_MAPPER |
| 52 | .writerWithDefaultPrettyPrinter() |
| 53 | .writeValueAsString(response)); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | protected void echo(final String msg) { |
| 58 | runtime.println(msg); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public Options getOptions() { |
| 63 | return new Options() |
| 64 | .addOption(CommonCLIOptions.HELP_OPTION) |
| 65 | .addOption(CommonCLIOptions.VERBOSE_OPTION); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public ToolRuntime getRuntime() { |
| 70 | return runtime; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Provides the connection options for CLI Tools: {@code --solr-url}, {@code --zk-host}, and the |
| 75 | * unified {@code --solr-connection} (which accepts either form). |
| 76 | * |
| 77 | * @return OptionGroup that enforces only one of the connection options is supplied. |
| 78 | */ |
| 79 | public OptionGroup getConnectionOptions() { |
| 80 | OptionGroup optionGroup = new OptionGroup(); |
| 81 | optionGroup.addOption(CommonCLIOptions.SOLR_URL_OPTION); |
| 82 | optionGroup.addOption(CommonCLIOptions.ZK_HOST_OPTION); |
| 83 | optionGroup.addOption(CommonCLIOptions.SOLR_CONNECTION_OPTION); |
| 84 | return optionGroup; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…