我正在开发一个非常简单的Symfony控制台应用程序。它只有一个带有一个参数的命令,以及几个选项。
我按照本指南创建了Application该类的扩展。
这是该应用程序的正常用法,并且工作正常:
php application <argument>
这也很好用(带有选项的参数):
php application.php <argument> --some-option
如果有人在运行时php application.php没有任何参数或选项,那么我希望它像用户在运行一样运行php application.php --help。
我确实有一个可行的解决方案,但它不是最佳解决方案,可能有点脆弱。在扩展Application类中,我run()按如下方式覆盖了该方法:
/**
* Override parent method so that --help options is used when app is called with no arguments or options
*
* @param InputInterface|null $input
* @param OutputInterface|null $output
* @return int
* @throws \Exception
*/
public function run(InputInterface $input = null, OutputInterface $output = null)
{
if ($input === null) { …Run Code Online (Sandbox Code Playgroud)