protected function getWriter(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
    {
        $outputFile = $input->getOption('output');
        if ($input->getOption('edit')) {
            if ($outputFile !== $this->getDefinition()->getOption('output')->getDefault()) {
                throw new \InvalidArgumentException("You cannot specify both --edit (-e) and --output (-f)");
            }
            $outputFile = $input->getOption('edit');
        }

        $writer = Writer\Factory::createWriter($input->getOption('output-format') ?: $input->getOption('input-format') ?: 'json');
        if (null === $outputFile && $output instanceof Console\Output\StreamOutput) {
            $writer->setOutput($output->getStream());
        } else {
            $writer->setOutput(fopen($outputFile ?: 'php://stdout', 'w'));
        }
        return $writer;
    }