This class represents a shell command.
Автор: Michael Härtl (haertl.mike@gmail.com)
Пример #1
0
 /**
  * Execute tor command
  *
  * @param $command
  * @return Command|string
  */
 public function command($command)
 {
     if (!in_array($command, ['start', 'stop', 'restart', 'reload', 'force-reload', 'status'])) {
         throw new \InvalidArgumentException($command);
     }
     $command = 'sudo /etc/init.d/tor ' . $command;
     $command = new Command($command);
     $command->execute();
     return $command;
 }
Пример #2
0
 public function up()
 {
     preg_match('/host=([^;]*)/', $this->db->dsn, $hostMatches);
     $hostName = $hostMatches[1];
     preg_match('/dbname=([^;]*)/', $this->db->dsn, $databaseMatches);
     $databaseName = $databaseMatches[1];
     preg_match('/port=([^;]*)/', $this->db->dsn, $portMatches);
     if (isset($portMatches[1])) {
         $port = $portMatches[1];
     } else {
         $port = "3306";
     }
     $command = new Command($this->mysqlExecutable);
     $command->addArg('-h', $hostName);
     $command->addArg('-P', $port);
     $command->addArg('-u', $this->db->username);
     $command->addArg('--password=', $this->db->password);
     $cmd = $command->getExecCommand() . " \"{$databaseName}\" < \"{$this->file}\"";
     #echo "    ".$cmd . "\n"; // TODO echo only with --verbose
     exec($cmd, $output, $return);
     if ($return !== 0) {
         //var_dump($output, $return);
         return false;
     } else {
         return true;
     }
 }
Пример #3
0
 /**
  * Displays application version from git describe and writes it to `version`
  */
 public function actionVersion($alias = '@app/version')
 {
     echo "Application Version\n";
     $cmd = new Command("git describe --dirty");
     if ($cmd->execute()) {
         echo $cmd->getOutput();
         file_put_contents(\Yii::getAlias($alias), $cmd->getOutput());
     } else {
         echo $cmd->getOutput();
         echo $cmd->getStdErr();
         echo $cmd->getError();
     }
     echo "\n";
 }
Пример #4
0
 /**
  * @return string|bool the command to execute with optional Xfvb wrapper applied. Null if none set.
  */
 public function getExecCommand()
 {
     $command = parent::getExecCommand();
     if ($this->enableXvfb) {
         return $this->xvfbRunBinary . ' ' . $this->xvfbRunOptions . ' ' . $command;
     }
     return $command;
 }
Пример #5
0
 /**
  * Generate application and required vendor documentation
  */
 public function actionGenerateDocs()
 {
     if ($this->confirm('Regenerate documentation files into ./docs-html', true)) {
         // array with commands
         $commands[] = 'vendor/bin/apidoc guide --interactive=0 docs web/apidocs';
         $commands[] = 'vendor/bin/apidoc api --interactive=0 --exclude=runtime/,tests/,vendor/ . web/apidocs';
         $commands[] = 'vendor/bin/apidoc guide --interactive=0 docs web/apidocs';
         foreach ($commands as $command) {
             $cmd = new Command($command);
             if ($cmd->execute()) {
                 echo $cmd->getOutput();
             } else {
                 echo $cmd->getOutput();
                 echo $cmd->getStdErr();
                 echo $cmd->getError();
             }
         }
     }
 }
Пример #6
0
 /**
  * @param $cmd
  *
  * @return mixed
  * @throws Exception
  */
 private function execute($cmd)
 {
     $command = new Command();
     $command->setCommand($cmd);
     if ($command->execute()) {
         return $command->getOutput();
     } else {
         throw new Exception($command->getError());
     }
 }
Пример #7
0
 /**
  * @param string|null $filename the filename to add as 'output' option or null if none
  * @return bool whether the command was executed successfully
  */
 public function execute($filename = null)
 {
     $this->checkExecutionStatus();
     $this->processInputFiles();
     $this->processOperation();
     $this->processOptions($filename);
     return parent::execute();
 }
Пример #8
0
 /**
  * Execute docker-compose commande
  * @codeCoverageIgnore
  * @param Command $command The command to execute.
  */
 protected function execute($command)
 {
     if ($command->execute()) {
         $output = $command->getOutput();
     } else {
         $output = $command->getError();
     }
     return array('output' => $output, 'code' => $command->getExitCode());
 }
Пример #9
0
 public function testCanProvideProcDir()
 {
     $tmpDir = sys_get_temp_dir();
     $command = new Command('pwd');
     $command->procCwd = $tmpDir;
     $this->assertFalse($command->getExecuted());
     $this->assertTrue($command->execute());
     $this->assertTrue($command->getExecuted());
     $this->assertEquals($tmpDir, $command->getOutput());
 }