Search in sources :

Example 1 with CliOptions

use of org.apache.flink.table.client.cli.CliOptions in project flink by apache.

the class SqlClient method startClient.

@VisibleForTesting
protected static void startClient(String[] args, Supplier<Terminal> terminalFactory) {
    final String mode;
    final String[] modeArgs;
    if (args.length < 1 || args[0].startsWith("-")) {
        // mode is not specified, use the default `embedded` mode
        mode = MODE_EMBEDDED;
        modeArgs = args;
    } else {
        // mode is specified, extract the mode value and reaming args
        mode = args[0];
        // remove mode
        modeArgs = Arrays.copyOfRange(args, 1, args.length);
    }
    switch(mode) {
        case MODE_EMBEDDED:
            final CliOptions options = CliOptionsParser.parseEmbeddedModeClient(modeArgs);
            if (options.isPrintHelp()) {
                CliOptionsParser.printHelpEmbeddedModeClient();
            } else {
                try {
                    final SqlClient client = new SqlClient(true, options, terminalFactory);
                    client.start();
                } catch (SqlClientException e) {
                    // make space in terminal
                    System.out.println();
                    System.out.println();
                    LOG.error("SQL Client must stop.", e);
                    throw e;
                } catch (Throwable t) {
                    // make space in terminal
                    System.out.println();
                    System.out.println();
                    LOG.error("SQL Client must stop. Unexpected exception. This is a bug. Please consider filing an issue.", t);
                    throw new SqlClientException("Unexpected exception. This is a bug. Please consider filing an issue.", t);
                }
            }
            break;
        case MODE_GATEWAY:
            throw new SqlClientException("Gateway mode is not supported yet.");
        default:
            CliOptionsParser.printHelpClient();
    }
}
Also used : CliOptions(org.apache.flink.table.client.cli.CliOptions) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 CliOptions (org.apache.flink.table.client.cli.CliOptions)1