protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     $sshUrl = $this->getSelectedEnvironment()->getSshUrl($input->getOption('app'));
     if ($input->getOption('pipe') || !$this->isTerminal($output)) {
         $output->write($sshUrl);
         return 0;
     }
     $remoteCommand = $input->getArgument('cmd');
     if ($input instanceof ArgvInput) {
         $helper = new ArgvHelper();
         $remoteCommand = $helper->getPassedCommand($this, $input);
     }
     $sshOptions = 't';
     // Pass through the verbosity options to SSH.
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
         $sshOptions .= 'vv';
     } elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
         $sshOptions .= 'v';
     } elseif ($output->getVerbosity() <= OutputInterface::VERBOSITY_NORMAL) {
         $sshOptions .= 'q';
     }
     $command = "ssh -{$sshOptions} " . escapeshellarg($sshUrl);
     if ($remoteCommand) {
         $command .= ' ' . escapeshellarg($remoteCommand);
     }
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
         $this->stdErr->writeln("Running command: <info>{$command}</info>");
     }
     passthru($command, $returnVar);
     return $returnVar;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     if ($input instanceof ArgvInput) {
         $helper = new ArgvHelper();
         $drushCommand = $helper->getPassedCommand($this, $input);
     }
     if (empty($drushCommand)) {
         $drushCommand = $input->getArgument('cmd');
     }
     $sshOptions = '';
     // Pass through options that the CLI shares with Drush and SSH.
     foreach (array('yes', 'no', 'quiet') as $option) {
         if ($input->getOption($option)) {
             $drushCommand .= " --{$option}";
         }
     }
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
         $drushCommand .= " --debug";
         $sshOptions .= ' -vv';
     } elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
         $drushCommand .= " --verbose";
         $sshOptions .= ' -v';
     } elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
         $drushCommand .= " --verbose";
     } elseif ($output->getVerbosity() == OutputInterface::VERBOSITY_QUIET) {
         $drushCommand .= " --quiet";
         $sshOptions .= ' -q';
     }
     $selectedEnvironment = $this->getSelectedEnvironment();
     $sshUrl = $selectedEnvironment->getSshUrl($input->getOption('app'));
     // The PLATFORM_DOCUMENT_ROOT environment variable is new. Default to
     // /app/public for backwards compatibility.
     $appRoot = '${PLATFORM_DOCUMENT_ROOT:-/app/public}';
     $dimensions = $this->getApplication()->getTerminalDimensions();
     $columns = $dimensions[0] ?: 80;
     $sshDrushCommand = "COLUMNS={$columns} drush --root=\"{$appRoot}\"";
     if ($environmentUrl = $selectedEnvironment->getLink('public-url')) {
         $sshDrushCommand .= " --uri=" . escapeshellarg($environmentUrl);
     }
     $sshDrushCommand .= ' ' . $drushCommand . ' 2>&1';
     $command = 'ssh' . $sshOptions . ' ' . escapeshellarg($sshUrl) . ' ' . escapeshellarg($sshDrushCommand);
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
         $this->stdErr->writeln("Running command: <info>{$command}</info>");
     }
     passthru($command, $return_var);
     return $return_var;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     if ($input instanceof ArgvInput) {
         $helper = new ArgvHelper();
         $drushCommand = $helper->getPassedCommand($this, $input);
     }
     if (empty($drushCommand)) {
         $drushCommand = $input->getArgument('cmd');
     }
     $sshOptions = '';
     // Pass through options that the CLI shares with Drush and SSH.
     foreach (['yes', 'no', 'quiet'] as $option) {
         if ($input->getOption($option)) {
             $drushCommand .= " --{$option}";
         }
     }
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
         $drushCommand .= " --debug";
         $sshOptions .= ' -vv';
     } elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
         $drushCommand .= " --verbose";
         $sshOptions .= ' -v';
     } elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
         $drushCommand .= " --verbose";
     } elseif ($output->getVerbosity() == OutputInterface::VERBOSITY_QUIET) {
         $drushCommand .= " --quiet";
         $sshOptions .= ' -q';
     }
     $appName = $this->selectApp($input, function (LocalApplication $app) {
         return Drupal::isDrupal($app->getRoot());
     });
     $selectedEnvironment = $this->getSelectedEnvironment();
     $sshUrl = $selectedEnvironment->getSshUrl($appName);
     // Get the LocalApplication object for the specified application, if
     // available.
     $projectRoot = $this->getProjectRoot();
     if ($projectRoot && $this->selectedProjectIsCurrent() && is_dir($projectRoot . '/' . LocalProject::REPOSITORY_DIR)) {
         $apps = LocalApplication::getApplications($projectRoot . '/' . LocalProject::REPOSITORY_DIR);
         if (count($apps) === 1 && $appName === null) {
             $app = reset($apps);
         } else {
             foreach ($apps as $possibleApp) {
                 if ($possibleApp->getName() === $appName) {
                     $app = $possibleApp;
                     break;
                 }
             }
         }
     }
     // Use the local application configuration (if available) to determine
     // the correct Drupal root.
     if (isset($app) && isset($app->getConfig()['web']['document_root'])) {
         $documentRoot = trim($app->getConfig()['web']['document_root'], '/') ?: 'public';
         $drupalRoot = '/app/' . $documentRoot;
     } else {
         // Fall back to the PLATFORM_DOCUMENT_ROOT environment variable,
         // which is usually correct, except where the document_root was
         // specified as '/'.
         $drupalRoot = '${PLATFORM_DOCUMENT_ROOT:-/app/public}';
         $this->debug('<comment>Warning:</comment> using $PLATFORM_DOCUMENT_ROOT for the Drupal root. This fails in cases where the document_root is /.');
     }
     $dimensions = $this->getApplication()->getTerminalDimensions();
     $columns = $dimensions[0] ?: 80;
     $sshDrushCommand = "COLUMNS={$columns} drush --root=\"{$drupalRoot}\"";
     if ($environmentUrl = $selectedEnvironment->getLink('public-url')) {
         $sshDrushCommand .= " --uri=" . escapeshellarg($environmentUrl);
     }
     $sshDrushCommand .= ' ' . $drushCommand . ' 2>&1';
     $command = 'ssh' . $sshOptions . ' ' . escapeshellarg($sshUrl) . ' ' . escapeshellarg($sshDrushCommand);
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
         $this->stdErr->writeln("Running command: <info>{$command}</info>");
     }
     passthru($command, $return_var);
     return $return_var;
 }