public function testCanAddMultipleParams()
 {
     $command = new Command('ls');
     $command->addParam(new Param('/srv'));
     $command->addParam(new Param('/var'));
     $this->assertEquals("ls '/srv' '/var'", (string) $command, 'Command should have multiple options');
 }
 /**
  * @return bool
  */
 public function checkLibaryIsInstalled()
 {
     $shell = new Exec();
     $command = new Command($this->binaryPath);
     $command->addArgument(new Command\Argument('version'));
     $shell->run($command);
     if ($shell->getReturnValue() === 0) {
         return true;
     }
     return false;
 }
Exemple #3
0
 /**
  * Execute FB command to display provided file
  *
  * @param $file Absolute path to the file to display.
  * @return bool If command was successful or not
  */
 public function publish($file)
 {
     $sudo = $this->_config['use_sudo'] ? "sudo " : "";
     $command = new Command($sudo . $this->_config['bin_path']);
     // Flags
     foreach ($this->_config['flags'] as $flag) {
         $command->addFlag(new Flag($flag));
     }
     $command->addParam(new Param($file));
     if ($this->_shell->run($command)) {
         $this->setStatusFile($file);
         return true;
     }
     return false;
 }
Exemple #4
0
 /**
  * {@inheritDoc}
  * 
  * @see \HcpssBanderson\Provider\ProviderInterface::assemble()
  */
 public function assemble(array $params)
 {
     $params = $this->resolveParams($params);
     $ds = DIRECTORY_SEPARATOR;
     $tempLocation = vsprintf('%s%s%s', [sys_get_temp_dir(), DIRECTORY_SEPARATOR, uniqid($this->getRepoName($params['source']))]);
     $shell = new ShellExec();
     // Clone the repository
     $cloneCommand = new CommandBuilder('git');
     $cloneCommand->addParam('clone')->addParam($params['source'])->addParam($tempLocation);
     $shell->run($cloneCommand);
     // Checkout the branch
     $checkoutCommand = new CommandBuilder('git');
     $checkoutCommand->addFlag('C', $tempLocation)->addParam('checkout')->addParam($params['branch']);
     $shell->run($checkoutCommand);
     // Delete the .git directory
     $ungitCommand = new CommandBuilder('rm');
     $ungitCommand->addFlag('rf')->addParam($tempLocation . $ds . '.git');
     $shell->run($ungitCommand);
     // Create the install location
     $destination = $this->projectBase;
     if ($params['destination']) {
         $destination .= $ds . $params['destination'];
     }
     if (!empty($params['rename'])) {
         $destination .= $ds . $params['rename'];
     }
     if (!file_exists($destination)) {
         $makeDestCmd = new CommandBuilder('mkdir');
         $makeDestCmd->addFlag('p')->addParam($destination);
         $shell->run($makeDestCmd);
     }
     // Move to the install location
     $moveCommand = new Command('mv');
     $moveCommand->addParam(new Param($tempLocation . $ds . '*', false));
     $moveCommand->addParam(new Param($destination, false));
     // Hidden files have to be specially invited
     $moveHiddenCommand = new Command('mv');
     $moveHiddenCommand->addParam(new Param($tempLocation . $ds . '.[!.]*', false));
     $moveHiddenCommand->addParam(new Param($destination, false));
     $shell->run($moveCommand);
     $shell->run($moveHiddenCommand);
     // Remove the old git folder
     $cleanTempCommand = new CommandBuilder('rm');
     $cleanTempCommand->addFlag('rf')->addParam($tempLocation);
     $shell->run($cleanTempCommand);
 }
<?php

require 'vendor/autoload.php';
use AdamBrett\ShellWrapper\Command;
use AdamBrett\ShellWrapper\Command\Param;
use AdamBrett\ShellWrapper\Runners\Exec;
$shell = new Exec();
$command = new Command('echo');
$command->addParam(new Param('Bonjour'));
$shell->run($command);
$shell2 = new Exec();
$command2 = new Command('echo');
$command2->addParam(new Param('Saviez-vous que les fourmis sont parfois paresseuses ?'));
$shell2->run($command2);
/*
$command3 = new Command('ls');
$shell->run($command3);
print_r($shell->getOutput()); 
*/