Esempio n. 1
0
 /**
  * Retrieves the synopsis of a given command or subcommand
  *
  * @param mixed $command The command or subcommand to get documentation on
  * @return array
  */
 private function getMarkdown($command)
 {
     $name = implode(' ', Dispatcher\getPath($command));
     $binding = array('name' => $name, 'shortdesc' => $command->getShortdesc(), 'synopsis' => $command->getSynopsis(), 'subcommands' => null, 'options' => $this->getOptions($command));
     if ($command->canHaveSubcommands()) {
         $binding['subcommands'] = $this->getSubcommands($command);
     }
     return $binding;
 }
Esempio n. 2
0
 /**
  * Retrieves the synopsis of a given command or subcommand
  *
  * @param [mixed] $command The command or subcommand to get documentation on
  * @return [string] $rendered_help
  */
 private function getInitialMarkdown($command)
 {
     $name = implode(' ', Dispatcher\getPath($command));
     $binding = array('name' => $name, 'shortdesc' => $command->getShortdesc());
     $binding['synopsis'] = wordwrap($name . ' ' . $command->getSynopsis(), 79);
     if ($command->canHaveSubcommands()) {
         $binding['has-subcommands']['subcommands'] = $this->renderSubcommands($command);
     }
     if (Terminus::getConfig('format') == 'json') {
         $rendered_help = $binding;
     } else {
         $rendered_help = Utils\mustacheRender('man.mustache', $binding);
     }
     return $rendered_help;
 }
Esempio n. 3
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
  * @return [void]
  */
 static function addCommand($name, $class)
 {
     $path = preg_split('/\\s+/', $name);
     $leaf_name = array_pop($path);
     $full_path = $path;
     $command = self::getRootCommand();
     while (!empty($path)) {
         $subcommand_name = $path[0];
         $subcommand = $command->findSubcommand($path);
         // Create an empty container
         if (!$subcommand) {
             $subcommand = new Dispatcher\CompositeCommand($command, $subcommand_name, new DocParser(''));
             $command->addSubcommand($subcommand_name, $subcommand);
         }
         $command = $subcommand;
     }
     $leaf_command = Dispatcher\CommandFactory::create($leaf_name, $class, $command);
     if (!$command->canHaveSubcommands()) {
         throw new TerminusException(sprintf("'%s' can't have subcommands.", implode(' ', Dispatcher\getPath($command))));
     }
     $command->addSubcommand($leaf_name, $leaf_command);
 }
Esempio n. 4
0
 public function testGetPath()
 {
     $root_command = Terminus::getRootCommand();
     $path = Dispatcher\getPath($root_command);
     $this->assertEquals($path, ['terminus']);
 }
Esempio n. 5
0
File: help.php Progetto: andrefy/cli
 private static function get_initial_markdown($command)
 {
     $name = implode(' ', Dispatcher\getPath($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);
     }
     if (Terminus::getConfig('format') == 'json') {
         $rendered_help = $binding;
     } else {
         $rendered_help = Utils\mustacheRender('man.mustache', $binding);
     }
     return $rendered_help;
 }