Convert console command options to ssh program options.

@param InputInterface $input
@param OutputInterface $output

@return array
13054
protected function getProgramOptions(
        InputInterface $input,
        OutputInterface $output
    ) {
        $opts = array();

        foreach ($this->getDefinition()->getOptions() as $o) {
            $name = $o->getName();
            if (! array_key_exists($name, $this->programOptions )) {
                continue;
            }
            $value = $input->getOption($name);
            if ($o->acceptValue() && $value !== null) {
                $opts[$this->programOptions[$name]] = $value;
            } else if (! $o->acceptValue() && $value === true) {
                $opts[] = $this->programOptions[$name];
            }
        }

        return array_merge(
            $opts,
            $this->getVerbosityOptions($output->getVerbosity())
        );
    }
1024532
private function setupData($input, $output)
    {
        $command = $this->getApplication()->find('networking:initcms:data-setup');
        $arguments = [
            'command' => 'networking:initcms:data-setup',
            '--drop' => true,
            '--use-acl' => $input->getOption('use-acl'),
        ];

        $input = new ArrayInput($arguments);

        return $command->run($input, $output);
    }
318522
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $verbosity = PhpVersions::VERBOSITY_NORMAL;
        $verbosity = $input->getOption('verbose') == 2 ? PhpVersions::VERBOSITY_VERBOSE : $verbosity;
        $verbosity = $input->getOption('verbose') == 3 ? PhpVersions::VERBOSITY_DEBUG : $verbosity;
        $verbosity = $input->getOption('quiet') ? PhpVersions::VERBOSITY_SILENT : $verbosity;
        $phpVersions = new PhpVersions(null, $verbosity);

        $versions = $input->getArgument('php');
        $version = array_shift($versions);
        if (empty($version)) {
            $version = 'latest';
        }

        $type = $input->getOption('type');
        if (empty($type)) {
            $type = 'sha256';
        }

        $format = $input->getOption('format');
        if (empty($format)) {
            $format = null;
        }

        $info = $phpVersions->getSourceInfo($version, $format);

        $output->write(isset($info[$type]) ? $info[$type] : '');
    }
346397
protected function getOptions(InputInterface $input)
    {
        return [
            'dir'    => (bool) $input->getOption('fix_dir'),
            'file'   => (bool) $input->getOption('fix_file'),
            'skip'   => (bool) $input->getOption('skip_dir_file'),
            'strict' => (bool) $input->getOption('strict_types'),
        ];
    }
1242561
protected function runCommand(InputInterface $input, OutputInterface $output)
    {
        $appName = $input->getArgument('app-name');
        $indices = $this
            ->repositoryBucket
            ->findRepository($appName)
            ->getIndices();

        self::printIndices(
            $input,
            $output,
            $indices
        );
    }
554408
public function execute(InputInterface $input, OutputInterface $output)
    {
        $source = $this->loadFiles($input->getArgument('source'));

        $this->rivescript->load($source);

        $loadedSource = explode('/', $input->getArgument('source'));
        $loadedSource = end($loadedSource);

        $output->writeln('RiveScript Interpreter (PHP) -- Interactive Console v2.0');
        $output->writeln('--------------------------------------------------------');
        $output->writeln('RiveScript Version:       2.0');
        $output->writeln('Currently Loaded Source:  '.$loadedSource);
        $output->writeln('');
        $output->writeln('You are now chatting with a RiveScript bot. Type a message and press Return');
        $output->writeln('to send it. When finished, type "/quit" to exit the interactive console.');
        $output->writeln('');

        $this->waitForUserInput($input, $output);
    }
1014081
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $start = microtime(true);

        $this->setOutput($output);
        $this->setVerbosity($output->getVerbosity());

        if ($input->getOption('child') && $output->getVerbosity() <= OutputInterface::VERBOSITY_NORMAL) {
            $this->setVerbosity(self::VERBOSITY_CHILD);
        }

        $this->getContainer()->get('ez_migration_bundle.step_executed_listener.tracing')->setOutput($output);

        $migrationService = $this->getMigrationService();

        $force = $input->getOption('force');

        $toExecute = $this->buildMigrationsList($input->getOption('path'), $migrationService, $force);

        if (!count($toExecute)) {
            $output->writeln('<info>No migrations to execute</info>');
            return 0;
        }

        $this->printMigrationsList($toExecute, $input, $output);

        if (!$input->getOption('child')) {
            // ask user for confirmation to make changes
            if (!$this->askForConfirmation($input, $output)) {
                return 0;
            }
        }

        if ($input->getOption('separate-process')) {
            $builder = new ProcessBuilder();
            $executableFinder = new PhpExecutableFinder();
            if (false !== $php = $executableFinder->find()) {
                $builder->setPrefix($php);
            }
            $builderArgs = $this->createChildProcessArgs($input);
        }

        // For cli scripts, this means: do not die if anyone yanks out our stdout.
        if ($input->getOption('survive-disconnected-tty')) {
            ignore_user_abort(true);
        }

        // allow forcing handling of sigchild. Useful on eg. Debian and Ubuntu
        if ($input->getOption('force-sigchild-enabled')) {
            Process::forceSigchildEnabled(true);
        }

        $aborted = false;
        $executed = 0;
        $failed = 0;
        $skipped = 0;
        $total = count($toExecute);

        /** @var MigrationDefinition $migrationDefinition */
        foreach ($toExecute as $name => $migrationDefinition) {

            // let's skip migrations that we know are invalid - user was warned and he decided to proceed anyway
            if ($migrationDefinition->status == MigrationDefinition::STATUS_INVALID) {
                $output->writeln("<comment>Skipping $name</comment>");
                $skipped++;
                continue;
            }

            $this->writeln("<info>Processing $name</info>");

            if ($input->getOption('separate-process')) {

                try {
                    $this->executeMigrationInSeparateProcess($migrationDefinition, $migrationService, $builder, $builderArgs);

                    $executed++;
                } catch (\Exception $e) {
                    $failed++;


                    $errorMessage = $e->getMessage();
                    // we probably have already echoed the error message while the subprocess was executing, avoid repeating it
                    if ($errorMessage != $this->subProcessErrorString) {
                        if ($e instanceof AfterMigrationExecutionException) {
                            $errorMessage = "Failure after migration end! Reason: " . $errorMessage;
                        } else {
                            $errorMessage = "Migration failed! Reason: " . $errorMessage;
                        }

                        $this->writeErrorln("\n<error>$errorMessage</error>");
                    }

                    if (!$input->getOption('ignore-failures')) {
                        $aborted = true;
                        break;
                    }
                }

            } else {

                try {
                    $this->executeMigrationInProcess($migrationDefinition, $force, $migrationService, $input);

                    $executed++;
                } catch (\Exception $e) {
                    $failed++;

                    $this->writeErrorln("\n<error>Migration failed! Reason: " . $e->getMessage() . "</error>");

                    if (!$input->getOption('ignore-failures')) {
                        $aborted = true;
                        break;
                    }
                }

            }
        }

        $missed = $total - $executed - $failed - $skipped;

        if ($aborted) {
            if ($missed > 0) {
                $this->writeErrorln("\n<error>Migration execution aborted</error>");
            }
        } else {
            // NB: as per the Sf doc at https://symfony.com/doc/2.7/console/calling_commands.html, the 'cache:clear'
            // command should be run 'at the end', as they change some class definitions
            if ($input->getOption('clear-cache')) {
                $command = $this->getApplication()->find('cache:clear');
                $inputArray = new ArrayInput(array('command' => 'cache:clear'));
                $command->run($inputArray, $output);
            }
        }

        $this->writeln("\nExecuted $executed migrations, failed $failed, skipped $skipped" . ($missed ? ", missed $missed" : ''));

        $time = microtime(true) - $start;
        if ($input->getOption('separate-process')) {
            // in case of using subprocesses, we can not measure max memory used
            $this->writeln("<info>Time taken: ".sprintf('%.2f', $time)." secs</info>");
        } else {
            $this->writeln("<info>Time taken: ".sprintf('%.2f', $time)." secs, memory: ".sprintf('%.2f', (memory_get_peak_usage(true) / 1000000)). ' MB</info>');
        }

        return $failed;
    }
946925
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
        $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
        $errOutput->setVerbosity(OutputInterface::VERBOSITY_NORMAL);

        $context = json_decode($input->getOption('context') ?: '{}', true);
        $context['tenant_id'] = (string)$input->getOption('tenant-id');

        $nodeRef = NodeRef::fromString($input->getArgument('node-ref'));
        $consistent = $input->getOption('consistent') ? true : false;

        try {
            $node = $this->ncr->getNode($nodeRef, $consistent, $context);
            echo json_encode($node, $input->getOption('pretty') ? JSON_PRETTY_PRINT : 0) . PHP_EOL;
        } catch (\Throwable $e) {
            $errOutput->writeln($e->getMessage());
        }
    }
261780
public function getRepoURL(InputInterface $input, OutputInterface $output)
    {
        return 'git@github.com:' . $this->gitHubUsername($input,$output) . '/' . $this->repoName($input) . '.git';
    }
16468
protected function execute(InputInterface $input, OutputInterface $output)
    {

        $listType = $input->getArgument('option');

        switch ($listType) {
            case "help":

                $help = [
                    '<info>',
                    '*******************************************************',
                    '* typo3 alias:show                shows help          *',
                    '* typo3 show:aliases this         shows current alias *',
                    '* typo3 show:aliases help         shows help          *',
                    '*******************************************************',
                    '</info>',
                ];

                $output->writeln($help);

                break;
            case "this":
                $contents = Yaml\Yaml::parse(file_get_contents($this->filename));

                foreach ($contents as $key => $value ){
                    if($value["path"] == PATH_site){
                        $output->writeln('<info>You are here: </info><question>'.$key.'</question>');
                    }

                }


                break;
            default:

                $output->writeln("Type 'show:aliases help' to find out more commands.");

                $output->writeln('Reading existing alias file');
                $contents = Yaml\Yaml::parse(file_get_contents($this->filename));

                $aliasesOutput = array();

                foreach ($contents as $key => $value ){
                    $aliasesOutput[] = '<question>'.$key.':</question>';
                    foreach ($value as $key2 => $value2){
                        $aliasesOutput[] = '   <info>'.$key2.': </info><comment>'.$value2.'</comment>';
                    }

                }


                $output->writeln($aliasesOutput);
                break;
        }

        return 0;

    }
773421
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->startCommand($output);

        $configurationIdentifier = $input->getArgument('identifier');
        $configurationValue = json_decode($input->getArgument('value'), true);

        $this
            ->configurationManager
            ->set(
                $configurationIdentifier,
                $configurationValue
            );

        $this->printMessage(
            $output,
            'Configuration',
            'Saved configuration "' . $configurationIdentifier . '"'
        );

        $this->finishCommand($output);
    }
182651
protected function setDeployOptions(InputInterface $input, OutputInterface $output)
    {
        $project = ProjectX::getProjectType();

        if ($project instanceof DeployAwareInterface) {
            $command_io = new SymfonyStyle($input, $output);
            $command_io->title('Deploy Build Options');

            $form = (new Form())
                ->setInput($input)
                ->setOutput($output)
                ->setHelperSet($this->getHelperSet())
                ->addFields([
                    (new BooleanField('deploy', 'Setup build deploy?'))
                        ->setDefault(false)
                        ->setSubform(function ($subform, $value) {
                            if (true === $value) {
                                $subform->addFields([
                                    (new TextField('repo_url', 'Repository URL')),
                                ]);
                            }
                        })
                ])
                ->process();

            $results = $form->getResults();

            if (isset($results['deploy']) && !empty($results['deploy'])) {
                $this->options['deploy'] = $results['deploy'];
            }
        }

        return $this;
    }
448242
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->setIo($input, $output);

        /** @var Repository $config */
        $config = $this->container['config'];

        $sourceRepoPath = $config['source.directory'];
        $sourceRepoUrl = $config['source.git.url'];
        $sourceRepoBranch = $config['source.git.branch'];

        $this->checkSourceRepoSettings($sourceRepoPath, $sourceRepoUrl);

        $output->writeln([
            "<b>steak pull configuration:</b>",
            " Source repository remote is <path>{$sourceRepoUrl}</path>",
            " Source repository branch is <path>{$sourceRepoBranch}</path>",
            " Path to local repository is <path>{$sourceRepoPath}</path>",
        ], OutputInterface::VERBOSITY_VERBOSE);

        if ($this->files->exists($sourceRepoPath)) {

            $workingCopy = $this->git->workingCopy($sourceRepoPath);

            if ( ! $workingCopy->isCloned()) {
                throw new RuntimeException("<path>{$sourceRepoPath}</path> exists but is not a git repository.");
            }

            if ($workingCopy->getBranches()->head() != $sourceRepoBranch) {
                throw new RuntimeException("<path>{$sourceRepoPath}</path> exists but isn't on the <path>{$sourceRepoBranch}</path> branch.");
            }

            $this->git->streamOutput();
            $workingCopy->pull();

        } else {
            $output->writeln([
                "The source directory <path>$sourceRepoPath</path> does not exist.",
                "  Attempting clone from {$sourceRepoUrl}",
            ]);

            $this->git->streamOutput();
            $this->git->cloneRepository($sourceRepoUrl, $sourceRepoPath, [
                'single-branch' => true,
                'branch' => $sourceRepoBranch
            ]);

            $output->writeln("<info>Clone complete! Edit your sources in <path>{$sourceRepoPath}</path></info>");
        }

        $output->writeln("Try <comment>steak serve</comment> to fire up the local development server...");
    }
236040
protected function execute(InputInterface $input, OutputInterface $output)
    {
        // retrieve the current settings
        $options = $this->getCurrentOptions($input, $output);

        // check if docker is installed
        if (false === $this->commandExists('docker')) {
            $output->writeln('Docker is required to run DUnit.');
            return self::ERROR_CODE;
        }
        // loop over each of the docker images specified
        foreach ($options[self::OPTIONS_KEY_IMAGES] as $image) {
            if ($options[self::OPTIONS_KEY_PULL]) {
                passthru(sprintf(
                    self::DOCKER_COMMAND_PULL,
                    escapeshellarg($image)
                ));
                continue;
            }

            $output->writeln('Running against image '.$image);
            if ($options[self::OPTIONS_KEY_SYNTAX]) {
                $output->writeln('Checking syntax');
                // run the syntax checks
                $this->executeCommandForImage(
                    $image,
                    $options[self::OPTIONS_KEY_SYNTAXCOMMAND]
                );
            }
            if ($options[self::OPTIONS_KEY_UNITTESTS]) {
                $output->writeln('Running unit test suite');
                // run the unit tests
                $this->executeCommandForImage(
                    $image,
                    $options[self::OPTIONS_KEY_UNITTESTSCOMMAND]
                );
            }
        }
        return self::NO_ERROR;
    }
1037584
protected function setProjectOptions(InputInterface $input, OutputInterface $output)
    {
        $project = ProjectX::getProjectType();

        if ($project instanceof OptionFormAwareInterface) {
            $classname = get_class($project);

            $command_io = new SymfonyStyle($input, $output);
            $command_io->newLine(2);
            $command_io->title(sprintf('%s Project Options', $classname::getLabel()));

            $form = $project->optionForm();
            $form
                ->setInput($input)
                ->setOutput($output)
                ->setHelperSet($this->getHelperSet())
                ->process();

            $this->options[$classname::getTypeId()] = $form->getResults();
        }

        return $this;
    }
839861
private function getPassword(InputInterface $input, OutputInterface $output)
    {
        if ($pass = $input->getOption('pass')) {
            return $pass;
        }
        if ($pass = $this->getTransifexConfigValue('/pass')) {
            $this->writelnVerbose($output, 'Using transifex password specified in config.');

            return $pass;
        }
        if ($pass = getenv('transifexpass')) {
            $this->writelnVerbose($output, 'Using transifex password specified in environment.');

            return $pass;
        }
        if ($input->isInteractive()) {
            /** @var \Symfony\Component\Console\Helper\QuestionHelper $dialog */
            $dialog = $this->getHelperSet()->get('question');
            if ($pass = $dialog->ask($input, $output, (new Question('Transifex password:'))->setHidden(true))) {
                return $pass;
            }
        }

        throw new \RuntimeException('Error: you must either specify a password on the commandline or run interactive.');
    }
1040150
public function cli(InputInterface $input = null, OutputInterface $output = null)
  {
    $input = $input ?? new ArgvInput();
    $output = $output ?? new ConsoleOutput();

    $console = $this->getConsole();
    $this->_eventChannel->trigger(ConsolePrepareEvent::i($this->getContext(), $console, $input, $output));

    try
    {
      $exitCode = $console->run($input, $output);
    }
    catch(\Throwable $e)
    {
      $output->writeln("GENERIC EXCEPTION : " . $e->getCode());
      $output->writeln($e->getMessage());
      $exitCode = 1;
    }

    return $exitCode > 255 ? 255 : $exitCode;
  }