/** * Fine tune main command by adding subcommands * * @para array $paths Paths to various Phrekyll directories * @param array $config Loaded contents of phrekyll.yml * * @return \Phrekyll\Runner\Command */ private function configureCommand($paths, $config) { // options foreach ($config['command']['options'] as $name => $option) { $this->addOption($name, $option); } // commands $commands = CommandLine\Commands::getInstance()->setPath($paths['configs'] . 'commands'); foreach ($commands as $name => $data) { $this->registerCommand($name, $data); } return $this; }
private function getUsageHelp() { $commands = $this->sortCommands(CommandLine\Commands::getInstance()); $out = "usage: %bphrekyll%n %g<command>%n [options] [args]\n\n"; $out .= "Type 'phrekyll help <command>' for help on a specific command.\n"; $out .= "Type 'phrekyll ? help' for help on using help.\n"; $out .= "Type 'phrekyll --version' to see the program version and installed plugins.\n"; $out .= "\nAvailable commands:\n"; foreach ($commands as $name => $data) { $command = $data['command']; $out .= ' ' . $name; if (null !== $command['aliases']) { $out .= ' (' . implode(', ', $command['aliases']) . ')'; } $out .= "\n"; } return $out; }
/** * Search if an alias exists for this command * * @param string $file Command name (could be an alias) * @return string The real command file name * */ private function getRealCommandName($file) { $iter = CommandLine\Commands::getInstance(); $commands = array(); foreach ($iter as $name => $data) { $commands[$name] = $data; } ksort($commands); if (!file_exists($file)) { foreach ($commands as $command) { if (is_array($command["command"]["aliases"]) && in_array($file, $command["command"]["aliases"])) { return $command["command"]["name"]; } } } return $file; }