protected function getLoader(Console\Input\InputInterface $input)
    {
        $inputFile = $input->getOption('input');

        if ($input->getOption('edit')) {
            if ($inputFile !== $this->getDefinition()->getOption('input')->getDefault()) {
                throw new \InvalidArgumentException("You cannot specify both --edit (-e) and --input (-i)");
            }
            $inputFile = $input->getOption('edit');
        }

        if ($inputFile === '-') {
            $inputFile = 'php://stdin';
            if (!($inputFormat = $input->getOption('input-format'))) {
                $inputFormat = 'json';
            }
        } elseif (!($inputFormat = $input->getOption('input-format'))) {
            // guess type based on extension.
            $inputFormat = Loader\Factory::guessType($inputFile);
        }

        $input->setOption('input-format', $inputFormat);

        $loader = Loader\Factory::createLoader($inputFormat);
        $inputStream = fopen($inputFile, 'r');
        if (!$inputStream) {
            throw new \RuntimeException("Could not open input");
        }

        if ($input->getOption('buffer') || $input->getOption('edit')) {
            $tmp = fopen('php://memory', 'rw');
            fwrite($tmp, stream_get_contents($inputStream));
            fseek($tmp, 0);
            $inputStream = $tmp;
        }
        $loader->setInput($inputStream);
        return $loader;
    }