@VisibleForTesting
    static void startSqlGateway(PrintStream stream, String[] args) {
        SqlGatewayOptions cliOptions = SqlGatewayOptionsParser.parseSqlGatewayOptions(args);

        if (cliOptions.isPrintHelp()) {
            SqlGatewayOptionsParser.printHelpSqlGateway(stream);
            return;
        }

        // startup checks and logging
        EnvironmentInformation.logEnvironmentInfo(LOG, "SqlGateway", args);
        SignalHandler.register(LOG);
        JvmShutdownSafeguard.installAsShutdownHook(LOG);

        DefaultContext defaultContext =
                DefaultContext.load(
                        ConfigurationUtils.createConfiguration(cliOptions.getDynamicConfigs()),
                        Collections.emptyList(),
                        true);
        SqlGateway gateway =
                new SqlGateway(
                        defaultContext.getFlinkConfig(), SessionManager.create(defaultContext));
        try {
            Runtime.getRuntime().addShutdownHook(new ShutdownThread(gateway));
            gateway.start();
            gateway.waitUntilStop();
        } catch (Throwable t) {
            // User uses ctrl + c to cancel the Gateway manually
            if (t instanceof InterruptedException) {
                LOG.info("Caught " + t.getClass().getSimpleName() + ". Shutting down.");
                return;
            }
            // make space in terminal
            stream.println();
            stream.println();

            if (t instanceof SqlGatewayException) {
                // Exception that the gateway can not handle.
                throw (SqlGatewayException) t;
            } else {
                LOG.error(
                        "SqlGateway must stop. Unexpected exception. This is a bug. Please consider filing an issue.",
                        t);
                throw new SqlGatewayException(
                        "Unexpected exception. This is a bug. Please consider filing an issue.", t);
            }
        } finally {
            gateway.stop();
        }
    }
@Test
    void testPrintStartGatewayHelp() {
        String[] args = new String[] {"--help"};
        SqlGateway.startSqlGateway(new PrintStream(output), args);

        assertThat(output.toString())
                .contains(
                        "Start the Flink SQL Gateway as a daemon to submit Flink SQL.\n"
                                + "\n"
                                + "  Syntax: start [OPTIONS]\n"
                                + "     -D <property=value>   Use value for given property\n"
                                + "     -h,--help             Show the help message with descriptions of all\n"
                                + "                           options.\n\n");
    }