tyesty / console-bundle
为symfony/console添加一些不错的功能 - 这是huttopia/console-bundle的分支
1.3.3.2
2022-01-06 13:42 UTC
Requires
- php: >=7.1.2
- symfony/console: ^2.3|^3.0|^4.0|^5.0|^6.0
- symfony/framework-bundle: ^2.3|^3.0|^4.0|^5.0|^6.0
README
ConsoleBundle
允许排除某些命令。
例如,如果您不想在prod环境中使用doctrine:schema:update命令,现在您可以这样做了:
为doctrine:schema:update添加配置,以便为每个连接获取多个数据库的查询。
安装
composer require tyesty/console-bundle ^1.3
替换bin/console
的部分
# Replace use Symfony\Bundle\FrameworkBundle\Console\Application; by this one use Huttopia\ConsoleBundle\Application; # Add this line before $input = new ArgvInput(); $allCommands = \Huttopia\ConsoleBundle\CommandOption\AllCommandsOption::parseAllCommandsOption($argv); $input = new ArgvInput(); # Replace Application creation (it should be the last 2 lines of your bin/console) // $application = new Application($kernel); // $application->run($input); (new Application($kernel)) ->setAllCommands($allCommands) ->run($input);
Symfony <= 3
# app/AppKernel.php class AppKernel { public function registerBundles() { $bundles = [ new \Huttopia\ConsoleBundle\ConsoleBundle() ]; } }
Symfony >= 4
# config/bundles.php return [ Huttopia\ConsoleBundle\ConsoleBundle::class => ['all' => true] ];
排除命令
# Symfony <= 3: app/config/config.yml # Symfony >= 4: config/packages/console_bundle.yaml console: excluded: - 'foo:bar:baz' - 'bar:foo:baz'
隐藏命令列表的一部分
当您调用bin/console
或bin/console list
时,您会看到命令列表。
输出被切分为4部分
- Symfony版本、环境和调试模式状态
- 使用语法帮助
- 所有命令可用选项的帮助
- 命令列表
您可以为每个部分配置显示的详细程度。
详细程度可以是0
、1
(-v
)、2
(-vv
)或3
(-vvv
)。
# Symfony <= 3: app/config/config.yml # Symfony >= 4: config/packages/console_bundle.yaml console: list: symfonyVersionVerbosityLevel: 1 usageVerbosityLevel: 1 optionsVerbosityLevel: 1 availableCommandsVerbosityLevel: 0
部分命令着色
当您调用bin/console
或bin/console list
时,您会看到命令列表。
您可以为命令名称和描述的每个部分更改颜色
console:
list:
output:
# See https://symfony.com.cn/doc/current/console/coloring.html
styles:
foo:
foreground: cyan # 1st parameter of new OutputFormatterStyle()
background: green # 2nd parameter of new OutputFormatterStyle()
options: [bold, underscore] # 3rd parameter of new OutputFormatterStyle()
commands:
generate:benchmark: "<foo>%%s</>%%s%%s" # 1st %s is command name, 2nd is spaces between name and description and 3rd is the description
highlights: # Shortcut for "<highlight>%%s</>%%s<highlight>%%s</>" who will write command name and description in cyan instead of green and white
- 'cache:clear'
为多个数据库执行doctrine:schema:update
doctrine:schema:update对我们来说有一个主要问题:每个连接只管理一个数据库。
在我们的项目中,每个连接有多个数据库,所以doctrine:schema:update不会显示我们所有数据库的查询。
UpdateDatabaseSchemaCommand替换了doctrine:schema:update并调用所有配置数据库的旧doctrine:schema:update!
配置
# Symfony <= 3: app/config/config.yml # Symfony >= 4: config/packages/console_bundle.yaml console: databases: - database_name_1 - database_name_2