Exemple #1
0
 /**
  * Show a list of available options
  */
 protected function showOptions()
 {
     $this->writeln("Options:", Colors::YELLOW);
     $rows = array(array(Colors::colorize('--version', Colors::GREEN), "Show version number"), array(Colors::colorize('--working-dir=DIR', Colors::GREEN), "If specified, use the given directory as working directory"), array(Colors::colorize('--config=FILE', Colors::GREEN), "Use an alternative config file"));
     $formater = new TextFormater(array('indent' => 2));
     $table = new Table(null, $rows, array('border' => false, 'frame' => false));
     $this->writeln($formater->format($table->render()));
 }
 /**
  * Show available options and commands
  */
 protected function showCommands()
 {
     $formater = new TextFormater(array('indent' => 2));
     $this->writeln('Available commands:', Colors::YELLOW);
     $rows = [];
     foreach ($this->console->getCommands() as $name => $fqdn) {
         $help = Help::fromFQDN($fqdn);
         $rows[] = array(Colors::colorize($name, Colors::GREEN), $help->getShortDescription());
     }
     $table = new Widgets\Table(null, $rows, array('border' => false, 'frame' => false));
     $this->writeln($formater->format($table->render()));
 }
Exemple #3
0
 public function execute(array $args, array $options = array())
 {
     if (empty($args)) {
         $formater = new ConsoleKit\TextFormater(array('quote' => ' * '));
         $this->writeln('Available commands:', ConsoleKit\Colors::BLACK | ConsoleKit\Colors::BOLD);
         foreach ($this->console->getCommands() as $name => $fqdn) {
             if ($fqdn !== __CLASS__) {
                 $this->writeln($formater->format($name));
             }
         }
         $this->writeln("Use 'clamp help command' for more info");
     } else {
         $commandFQDN = $this->console->getCommand($args[0]);
         $help = ConsoleKit\Help::fromFQDN($commandFQDN, ConsoleKit\Utils::get($args, 1));
         $this->writeln($help);
     }
 }
Exemple #4
0
 /**
  * Writes an error message to stderr
  *
  * @param \Exception $e
  * @return Console
  */
 public function writeException(\Exception $e)
 {
     if ($this->verboseException) {
         $text = sprintf("[%s]\n%s\nIn %s at line %s\n%s", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
     } else {
         $text = sprintf("\n[%s]\n%s\n", get_class($e), $e->getMessage());
     }
     $box = new Widgets\Box($this->textWriter, $text, '');
     $out = Colors::colorizeLines($box, Colors::WHITE, Colors::RED);
     $out = TextFormater::apply($out, array('indent' => 2));
     $this->textWriter->writeln($out);
     return $this;
 }
Exemple #5
0
 /**
  * Show a lists with all updates and their status
  */
 public function showComplete()
 {
     $updates = $this->dbvc()->getUpdatesAvailable();
     if (empty($updates)) {
         if ($this->verbosity) {
             $this->writeln("No updates available");
         }
         return;
     }
     $done = $this->dbvc()->getUpdatesDone();
     $prefix = "";
     if ($this->verbosity) {
         $this->writeln("Available updates:", Colors::YELLOW);
     }
     if ($this->short) {
         $prefix = $this->verbosity ? "  " : '';
         foreach ($updates as $update) {
             $status = !in_array($update, $done) ? 'o' : 'x';
             $this->writeln($prefix . $status . ' ' . $update);
         }
     } else {
         $rows = array();
         foreach ($updates as $update) {
             $status = !in_array($update, $done) ? Colors::colorize('open', Colors::YELLOW) : Colors::colorize('done', Colors::GREEN);
             $rows[] = array($update, $status);
         }
         $formater = new \ConsoleKit\TextFormater(array('indent' => $this->verbosity ? 2 : 0));
         $table = new Table(null, $rows, array('border' => false, 'frame' => false));
         $this->writeln($formater->format($table->render()));
     }
 }
Exemple #6
0
 /**
  * Formats text using a {@see TextFormater}
  *
  * @param string $text
  * @param int|array $formatOptions Either an array of options for TextFormater or a color code
  * @return string
  */
 public function format($text, $formatOptions = array())
 {
     if (!is_array($formatOptions)) {
         $formatOptions = array('fgcolor' => $formatOptions);
     }
     $formatOptions = array_merge($this->defaultFormatOptions, $formatOptions);
     $formater = new TextFormater($formatOptions);
     return $formater->format($text);
 }
Exemple #7
0
 /**
  * Render subcommands
  * 
  * @return string
  */
 protected function renderSubcommands()
 {
     if (empty($this->subCommands)) {
         return null;
     }
     $rows = array();
     foreach ($this->subCommands as $name => $desc) {
         $rows[] = array(Colors::colorize($name, Colors::GREEN), $desc);
     }
     $table = new Widgets\Table(null, $rows, array('border' => false, 'frame' => false));
     $formater = new TextFormater(array('indent' => 2));
     return Colors::colorize("Sub commands:\n", Colors::YELLOW) . $formater->format($table->render()) . "\n";
 }