Esempio n. 1
0
 public static function throwEx($msg)
 {
     throw new \Exception(Utils::color($msg, "light_red"));
 }
Esempio n. 2
0
 /**
  * Add an error to the stack
  * @ignore
  * @param	string	$error	The error
  */
 public function _addError($error)
 {
     $warning = "Error: {$error}";
     $this->_adjustLen(0, 0, 0, strlen($warning));
     $this->errors[] = Utils::color(str_pad($warning, $this->maxTotaLen + 2, " ", STR_PAD_RIGHT), "bg_light_red", "white") . PHP_EOL;
 }
Esempio n. 3
0
 /**
  * @ignore
  */
 public function getHelpInfo()
 {
     $alias = empty($this->alias) ? "" : "|" . implode("|", $this->alias);
     $cmds = "  " . Utils::color($this->name, "bold") . str_pad($alias, $this->args->_getLen("name") + $this->args->_getLen("long") - strlen($this->name), " ", STR_PAD_RIGHT);
     $descs = $this->desc;
     $ret = "";
     for ($i = 0; $i < max(1, sizeof($descs)); $i++) {
         $ret .= $i == 0 ? $cmds . " -> " : str_repeat(" ", $this->args->_getLen("name") + $this->args->_getLen("long") + 6);
         $ret .= isset($descs[$i]) ? $descs[$i] : "";
         $ret .= PHP_EOL;
     }
     return $ret;
 }
Esempio n. 4
0
 /**
  * Get the help information for the option
  * @ignore
  * @return	string		The formatted help information of the option
  */
 public function getHelpInfo()
 {
     $optnames = [];
     if ($this->type == 'incr') {
         foreach ($this->shorts as $short) {
             $name = "-{$short}";
             for ($i = 1; $i < $this->incrMax; $i++) {
                 $name .= "|" . str_repeat($short, $i + 1);
             }
             $optnames[] = $name;
         }
         foreach ($this->longs as $long) {
             $optnames[] = "--{$long}";
         }
         $name = array_shift($optnames);
         $optname1st = "  " . Utils::color($name, "bold");
         $optname1st .= str_pad("", $this->command->_getLen("name") + $this->command->_getLen("long") - strlen($name), " ", STR_PAD_RIGHT);
     } else {
         foreach ($this->shorts as $short) {
             $optnames[] = "-{$short}";
         }
         foreach ($this->longs as $long) {
             $optnames[] = "--{$long}";
         }
         $name = array_shift($optnames);
         $optname1st = "  " . Utils::color($name, "bold");
         $optname1st .= str_pad(empty($optnames) ? "" : ",", $this->command->_getLen("name") - strlen($name), " ", STR_PAD_RIGHT);
         $optname1st .= empty($optnames) ? str_repeat(" ", $this->command->_getLen("Long")) : str_pad(array_shift($optnames), $this->command->_getLen("Long"), " ", STR_PAD_RIGHT);
     }
     $hoptnames = [$optname1st];
     foreach ($optnames as $optname) {
         $hoptname = "  ";
         $hoptname .= str_pad(str_repeat(" ", strlen($this->name) + 1) . ",", $this->command->_getLen("name"), " ", STR_PAD_RIGHT);
         $hoptname .= str_pad($optname, $this->command->_getLen("long"), " ", STR_PAD_RIGHT);
         $hoptnames[] = $hoptname;
     }
     $typestr = "";
     if ($this->command->_getShowTypes()) {
         $typestr = "[" . ucfirst($this->type) . (($this->type == "string" and !is_null($this->regexp)) ? "(" . $this->regexp . ")" : "") . "]";
         $this->command->_adjustLen(0, 0, strlen($typestr), 0);
         $desc = [Utils::color($typestr, "cyan")];
     } else {
         $desc = [];
     }
     $descs = array_merge($desc, $this->desc);
     if ($this->required) {
         $descs[] = Utils::color("Required.", "light_red");
     } else {
         if (!is_null($this->default) and $this->type != "flag") {
             $descs[] = Utils::color("Default: " . $this->getDefaultStr(), "green");
         }
     }
     $ret = "";
     for ($i = 0; $i < max(sizeof($hoptnames), sizeof($descs)); $i++) {
         $ret .= isset($hoptnames[$i]) ? $hoptnames[$i] : str_repeat(" ", $this->command->_getLen("name") + $this->command->_getLen("long") + 2);
         $ret .= $i == 0 ? " -> " : "    ";
         $ret .= isset($descs[$i]) ? $descs[$i] : "";
         $ret .= PHP_EOL;
     }
     return $ret;
 }