authserver/homestead/src/RunCommand.php
changeset 8 5a0cbbe0922a
equal deleted inserted replaced
7:1a3fa80225b2 8:5a0cbbe0922a
       
     1 <?php namespace Laravel\Homestead;
       
     2 
       
     3 use Symfony\Component\Process\Process;
       
     4 use Symfony\Component\Console\Command\Command;
       
     5 use Symfony\Component\Console\Input\InputArgument;
       
     6 use Symfony\Component\Console\Input\InputInterface;
       
     7 use Symfony\Component\Console\Output\OutputInterface;
       
     8 
       
     9 class RunCommand extends Command {
       
    10 
       
    11 	/**
       
    12 	 * Configure the command options.
       
    13 	 *
       
    14 	 * @return void
       
    15 	 */
       
    16 	protected function configure()
       
    17 	{
       
    18 		$this
       
    19 			->setName('run')
       
    20 			->setDescription('Run commands through the Homestead machine via SSH')
       
    21 			->addArgument('ssh-command', InputArgument::REQUIRED, 'The command to pass through to the virtual machine.');
       
    22 }
       
    23 
       
    24 	/**
       
    25 	 * Execute the command.
       
    26 	 *
       
    27 	 * @param  \Symfony\Component\Console\Input\InputInterface  $input
       
    28 	 * @param  \Symfony\Component\Console\Output\OutputInterface  $output
       
    29 	 * @return void
       
    30 	 */
       
    31 	public function execute(InputInterface $input, OutputInterface $output)
       
    32 	{
       
    33 		chdir(__DIR__.'/../');
       
    34 
       
    35 		$command = $input->getArgument('ssh-command');
       
    36 
       
    37 		passthru($this->setEnvironmentCommand() . ' vagrant ssh -c "'.$command.'"');
       
    38 	}
       
    39 
       
    40 	protected function setEnvironmentCommand()
       
    41 	{
       
    42 		if ($this->isWindows()) {
       
    43 			return 'SET VAGRANT_DOTFILE_PATH='.$_ENV['VAGRANT_DOTFILE_PATH'].' &&';
       
    44 		}
       
    45 
       
    46 		return 'VAGRANT_DOTFILE_PATH="'.$_ENV['VAGRANT_DOTFILE_PATH'].'"';
       
    47 	}
       
    48 
       
    49 	protected function isWindows()
       
    50 	{
       
    51 		return strpos(strtoupper(PHP_OS), 'WIN') === 0;
       
    52 	}
       
    53 	
       
    54 }