public int run(String[] args) {
        if (colorFormatter == null) {
            // CLI arguments haven't been parsed yet, so the CLI doesn't know if --force-color or --no-color
            // was passed. Defer the color setting implementation by asking StandardOptions before each write.
            colorFormatter(createDelegatedColorFormatter(standardOptions::colorSetting));
        }

        if (stdoutPrinter == null) {
            stdout(CliPrinter.fromOutputStream(System.out));
        }

        if (stderrPrinter == null) {
            stderr(CliPrinter.fromOutputStream(System.err));
        }

        LoggingArgumentsHandler arguments = new LoggingArgumentsHandler(colorFormatter,
                stderrPrinter,
                Arguments.of(args));
        arguments.addReceiver(standardOptions);

        try {
            try {
                Command.Env env = new Command.Env(colorFormatter, stdoutPrinter, stderrPrinter, classLoader);
                return command.execute(arguments, env);
            } catch (Exception e) {
                stdoutPrinter.flush();
                stderrPrinter.flush();
                printException(e, standardOptions.stackTrace());
                throw CliError.wrap(e);
            } finally {
                try {
                    arguments.restoreLogging();
                } catch (RuntimeException e) {
                    // Show the error, but don't fail the CLI since most invocations are one-time use.
                    printException(e, standardOptions.stackTrace());
                }
            }
        } finally {
            stdoutPrinter.flush();
            stderrPrinter.flush();
        }
    }
Execute the command line using the given arguments.

@param args Arguments to parse.
@return Returns the exit code.
@throws CliError on error.
smithy-cli/src/main/java/software/amazon/smithy/cli/Cli.java