@Override public String getInfoMessage() { if (config.hasPath(INFO_MESSAGE_TEMPLATE_CONF)) { String quote = ""; if (config.hasPath(QUOTES_CONF)) { List<String> quotes = config.getStringList(QUOTES_CONF); quote = quotes.get(new Random().nextInt(quotes.size())); } return String.format(config.getString(INFO_MESSAGE_TEMPLATE_CONF), getVersion(), quote); } return super.getInfoMessage(); }
@VisibleForTesting public DrillSqlLineApplication(String configName, String overrideConfigName) { this.config = overrideConfig(overrideConfigName, loadConfig(configName)); if (config.isEmpty()) { logger.warn("Was unable to find / load [{}]. Will use default SqlLine configuration.", configName); } }
private Config overrideConfig(String configName, Config config) { Config overrideConfig = loadConfig(configName); return overrideConfig.withFallback(config).resolve(); }
@Override public Collection<CommandHandler> getCommandHandlers(SqlLine sqlLine) { List<String> commandsToExclude = new ArrayList<>(); // exclude connect command and then add it back to ensure connection url examples are updated boolean reloadConnect = config.hasPath(CONNECTION_URL_EXAMPLES_CONF); if (reloadConnect) { commandsToExclude.add("connect"); } if (config.hasPath(COMMANDS_TO_EXCLUDE_CONF)) { commandsToExclude.addAll(config.getStringList(COMMANDS_TO_EXCLUDE_CONF)); } if (commandsToExclude.isEmpty()) { return sqlLine.getCommandHandlers(); } List<CommandHandler> commandHandlers = sqlLine.getCommandHandlers().stream() .filter(c -> c.getNames().stream() .noneMatch(commandsToExclude::contains)) .collect(Collectors.toList()); if (reloadConnect) { commandHandlers.add(new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getConnectionUrlExamples()), "connect", "open")); } return commandHandlers; }