private static CommandLineImpl ofRubyCommand(
            final Command command,
            final String commandString,
            final List<String> originalArgs,
            final String usage,
            final String header,
            final Logger logger) {
        final int index = originalArgs.indexOf(commandString);
        if (index < 0) {
            throw new IllegalStateException("Internal error: '" + commandString + "' is unexpectedly not found.");
        }

        final CommandWriters writers = new CommandWriters();
        final CommandLine commandLine = parse(originalArgs.subList(0, index + 1), COMMON_OPTIONS, usage, header, writers, logger);

        if (commandLine == null) {
            return CommandLineImpl.ofInvalid(command, writers);
        } else if (commandLine.hasOption(HELP.getOpt())) {
            printHelp(COMMON_OPTIONS, usage, header, writers.getStdOutWriter());
            return CommandLineImpl.ofInvalid(command, writers);
        }

        final String[] args = commandLine.getArgs();
        if (args.length != 1) {
            throw new IllegalStateException("Internal error: Arguments after '" + commandString + "' are unexpectedly processed.");
        }

        final Properties properties = new Properties();
        for (final Option option : commandLine.getOptions()) {
            processOptionToProperties(option, command, properties, logger);
        }

        return new CommandLineImpl(
                true,
                command,
                originalArgs.subList(index + 1, originalArgs.size()),
                properties,
                writers.getStdOut(),
                writers.getStdErr());
    }
Creates a CommandLineImpl instance for "gem" and "bundle" which pass-thorugh following arguments.
embulk-deps/src/main/java/org/embulk/deps/cli/CommandLineImpl.java