Ejemplo n.º 1
0
 /**
  * @param callable $callback
  */
 public static function execute(\Closure $callback)
 {
     if (static::$set_error_handler) {
         static::_setErrorHandler();
     }
     try {
         $callback();
     } catch (\Exception $e) {
         if (static::$beep_on_error) {
             Terminal::beep();
         }
         $msg = sprintf("PHP Fatal error:  Uncaught exception '%s' with message '%s' in %s:%s", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine());
         static::msgError($msg);
         static::errorLn('Stack trace:');
         static::errorLn(static::text($e->getTraceAsString())->bold());
         static::errorLn(sprintf(static::text('  thrown in %s on line %s')->bold(), $e->getFile(), $e->getLine()));
         exit(1);
     }
     exit(0);
 }
Ejemplo n.º 2
0
 /**
  * @return string help docs
  */
 public function getHelp()
 {
     $this->attachHelp();
     if (empty($this->name) && isset($this->tokens[0])) {
         $this->name = $this->tokens[0];
     }
     $color = new \Colors\Color();
     $help = '';
     $help .= $color(\Commando\Util\Terminal::header(' ' . $this->name))->white()->bg('green')->bold() . PHP_EOL;
     if (!empty($this->help)) {
         $help .= PHP_EOL . \Commando\Util\Terminal::wrap($this->help) . PHP_EOL;
     }
     $help .= PHP_EOL;
     $seen = array();
     $keys = array_keys($this->options);
     natsort($keys);
     foreach ($keys as $key) {
         $option = $this->getOption($key);
         if (in_array($option, $seen)) {
             continue;
         }
         $help .= $option->getHelp() . PHP_EOL;
         $seen[] = $option;
     }
     return $help;
 }
Ejemplo n.º 3
0
 /**
  * @return string
  */
 public function getHelp()
 {
     $color = new \Colors\Color();
     $help = '';
     $isNamed = $this->type & self::TYPE_NAMED;
     if ($isNamed) {
         $help .= PHP_EOL . (mb_strlen($this->name, 'UTF-8') === 1 ? '-' : '--') . $this->name;
         if (!empty($this->aliases)) {
             foreach ($this->aliases as $alias) {
                 $help .= (mb_strlen($alias, 'UTF-8') === 1 ? '/-' : '/--') . $alias;
             }
         }
         if (!$this->isBoolean()) {
             $help .= ' ' . $color->underline('<argument>');
         }
         $help .= PHP_EOL;
     } else {
         $help .= (empty($this->title) ? "arg {$this->name}" : $this->title) . PHP_EOL;
     }
     // bold what has been displayed so far
     $help = $color->bold($help);
     $titleLine = '';
     if ($isNamed && $this->title) {
         $titleLine .= $this->title . '.';
         if ($this->isRequired()) {
             $titleLine .= ' ';
         }
     }
     if ($this->isRequired()) {
         $titleLine .= $color->red('Required.');
     }
     if ($titleLine) {
         $titleLine .= ' ';
     }
     $description = $titleLine . $this->description;
     if (!empty($description)) {
         $descriptionArray = explode(PHP_EOL, trim($description));
         foreach ($descriptionArray as $descriptionLine) {
             $help .= Terminal::wrap($descriptionLine, 5, 1) . PHP_EOL;
         }
     }
     return $help;
 }