public function register_package() { self::withPackage('util.cmd.unittest', function ($package) { $this->assertEquals([Package::forName($package)], Commands::allPackages()); }); }
/** * Lists commands * * @return void */ protected function listCommands() { $commandsIn = function ($package) { $text = ''; foreach ($package->getClasses() as $class) { if ($class->isSubclassOf('util.cmd.Command') && !Modifiers::isAbstract($class->getModifiers())) { $text .= ' $ xpcli ' . $class->getSimpleName() . "\n"; } } return $text ?: ' (no commands)'; }; self::$err->writeLine('Named commands'); self::$err->writeLine(); if ($packages = Commands::allPackages()) { foreach (Commands::allPackages() as $package) { self::$err->writeLine('* ', $package); self::$err->writeLine($commandsIn($package)); } self::$err->writeLine(); } self::$err->writeLine('* Global package'); self::$err->writeLine($commandsIn(Package::forName(null))); }
/** * Lists commands * * @return void */ protected function listCommands() { $commandsIn = function ($package) { $markdown = ''; foreach ($package->getClasses() as $class) { if ($class->isSubclassOf('util.cmd.Command') && !Modifiers::isAbstract($class->getModifiers())) { $markdown .= ' $ xp cmd ' . $class->getSimpleName() . "\n"; } } return $markdown ?: ' *(no commands)*'; }; $markdown = "# Named commands\n\n"; if ($packages = Commands::allPackages()) { foreach ($packages as $package) { $markdown .= '* In package **' . $package->getName() . "**\n\n" . $commandsIn($package); } $markdown .= "\n"; } $markdown .= "* In global package\n\n" . $commandsIn(Package::forName(null)); Help::render(self::$err, $markdown, []); }