Пример #1
0
 private static function get_initial_markdown($command)
 {
     $name = implode(' ', Dispatcher\get_path($command));
     $binding = array('name' => $name, 'shortdesc' => $command->get_shortdesc());
     $binding['synopsis'] = wordwrap("{$name} " . $command->get_synopsis(), 79);
     if ($command->can_have_subcommands()) {
         $binding['has-subcommands']['subcommands'] = self::render_subcommands($command);
     }
     return Utils\mustache_render('man.mustache', $binding);
 }
Пример #2
0
 /**
  * Add a command to the terminus list of commands
  *
  * @param string $name The name of the command that will be used in the CLI
  * @param string $class The command implementation
  * @param array $args An associative array with additional parameters:
  *   'before_invoke' => callback to execute before invoking the command
  */
 static function add_command($name, $class, $args = array())
 {
     $path = preg_split('/\\s+/', $name);
     $leaf_name = array_pop($path);
     $full_path = $path;
     $command = self::get_root_command();
     while (!empty($path)) {
         $subcommand_name = $path[0];
         $subcommand = $command->find_subcommand($path);
         // create an empty container
         if (!$subcommand) {
             $subcommand = new Dispatcher\CompositeCommand($command, $subcommand_name, new \Terminus\DocParser(''));
             $command->add_subcommand($subcommand_name, $subcommand);
         }
         $command = $subcommand;
     }
     $leaf_command = Dispatcher\CommandFactory::create($leaf_name, $class, $command);
     if (!$command->can_have_subcommands()) {
         throw new Exception(sprintf("'%s' can't have subcommands.", implode(' ', Dispatcher\get_path($command))));
     }
     $command->add_subcommand($leaf_name, $leaf_command);
 }