Ejemplo n.º 1
0
 /**
  * @return ExecResult
  */
 public function execute()
 {
     echo Cli::getColoredString($this->command . PHP_EOL, 'light_blue');
     exec($this->command, $output, $return);
     $result = new ExecResult($return, $output);
     echo Cli::getColoredString(implode(PHP_EOL, $output), 'dark_gray') . "\n\n";
     return $result;
 }
Ejemplo n.º 2
0
 public function execute()
 {
     // detect max width
     $minColumnWidth = 30;
     foreach ($this->sections as $sectionName => $data) {
         if (strlen($sectionName) > $minColumnWidth) {
             $minColumnWidth = strlen($sectionName) + 5;
         }
         foreach ($data['tasks'] as $taskName => $description) {
             if (strlen($taskName) > $minColumnWidth) {
                 $minColumnWidth = strlen($taskName) + 2 + 5;
             }
         }
     }
     // empty section first
     if (isset($this->sections[''])) {
         $val = $this->sections[''];
         unset($this->sections['']);
         $this->sections = ['' => $val] + $this->sections;
     }
     echo Cli::getColoredString(str_repeat('-', 14), 'green') . PHP_EOL;
     echo Cli::getColoredString('HELP', 'green') . PHP_EOL;
     echo Cli::getColoredString(str_repeat('-', 14), 'green') . PHP_EOL . PHP_EOL;
     echo "Available tasks:" . PHP_EOL;
     foreach ($this->sections as $sectionName => $data) {
         echo Cli::getColoredString($sectionName, 'yellow');
         echo str_repeat(" ", $minColumnWidth - strlen($sectionName) + 2);
         // +2 = two spaces before taskName (below)
         echo Cli::getColoredString($data['description'], 'dark_gray');
         echo PHP_EOL;
         foreach ($data['tasks'] as $taskName => $description) {
             echo "  " . Cli::getColoredString($taskName, 'light_blue');
             echo str_repeat(" ", $minColumnWidth - strlen($taskName));
             echo Cli::getColoredString($description, 'gray');
             echo PHP_EOL;
         }
         echo PHP_EOL;
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $message
  * @param string|null $color
  * @param string|null $backgroundColor
  */
 private function log($message, $color = NULL, $backgroundColor = NULL)
 {
     echo Cli::getColoredString($message . PHP_EOL, $color, $backgroundColor);
 }
Ejemplo n.º 4
0
 protected function logSection($message)
 {
     echo Cli::getColoredString("=> " . $message, 'green') . PHP_EOL;
 }
Ejemplo n.º 5
0
 protected function log($message, $severity = NULL)
 {
     $color = isset(self::$severityColors[$severity]) ? self::$severityColors[$severity] : NULL;
     echo Cli::getColoredString($message . PHP_EOL, $color);
 }
Ejemplo n.º 6
0
 public function execute()
 {
     if (count($this->directoriesToCreate) > 0) {
         $this->log(Cli::getColoredString('Creating directories', 'light_blue'));
         $command = new Directory();
         foreach ($this->directoriesToCreate as $directory => $chmod) {
             if (is_dir($directory)) {
                 $this->log("Directory '{$directory}' already exists, skipping ...");
                 continue;
             }
             $command->create($directory, $chmod);
             $this->log("Directory '{$directory}' created.");
         }
     }
     if (count($this->directoriesToClean) > 0) {
         $this->log(Cli::getColoredString('Cleaning directories', 'light_blue'));
         $command = new Directory();
         foreach ($this->directoriesToClean as $directory) {
             $command->clean($directory);
             $this->log("Directory '{$directory}' cleaned.");
         }
     }
     if (count($this->filesToCopy) > 0) {
         $this->log(Cli::getColoredString('Copying files', 'light_blue'));
         $command = new File();
         foreach ($this->filesToCopy as $destination => $options) {
             if (is_file($destination)) {
                 if ($options['onDuplicate'] == self::ERROR) {
                     $this->error("File '{$destination}' already exists.");
                 } elseif ($options['onDuplicate'] == self::SKIP) {
                     $this->log("File '{$destination}' already exists, skipping ...");
                     continue;
                 } elseif ($options['onDuplicate'] == self::REWRITE) {
                     $command->delete($destination);
                 }
             }
             $command->copy($options['source'], $destination);
             $this->log("File '{$options['source']}' copied to '{$destination}'.");
         }
     }
     if (count($this->symlinksRelativeToCreate) > 0) {
         $this->log(Cli::getColoredString('Creating symlinks', 'light_blue'));
         $command = new \Genesis\Commands\Filesystem\Symlink();
         foreach ($this->symlinksRelativeToCreate as $baseDir => $symlinks) {
             foreach ($symlinks as $link => $target) {
                 $absoluteLinkPath = $baseDir . '/' . $link;
                 if (is_link($absoluteLinkPath)) {
                     $this->log("Symlink '{$link}' already exists, skipping ...");
                     continue;
                 }
                 $command->createRelative($baseDir, $target, $link);
                 $this->log("Symlink '{$link}' created.");
             }
         }
     }
 }