theroadbunch / command-menu
用于命令菜单的简单类
v1.0.0
2019-01-07 19:56 UTC
Requires
- php: ^7.1
- symfony/console: ^4.2
Requires (Dev)
- phpunit/phpunit: ^7.4
- symfony/var-dumper: ^4.2
This package is auto-updated.
Last update: 2024-09-08 08:57:24 UTC
README
symfony控制台命令的简单菜单
快速说明
此README假定您已经了解在symfony生态系统中创建和运行控制台命令的方法
内容
使用composer安装 [?]
composer require theroadbunch/command-menu
基本用法
在symfony控制台命令中创建、渲染和使用菜单
<?php // ... use RoadBunch\CommandMenu\Menu; use RoadBunch\CommandMenu\Option; // ... public function execute(InputInterface $input, OutputInterface $output) { // create the menu $menu = new Menu($input, $output); // optional title $menu->title('Options'); // add options $menu->addOption('add', 'Add User'); $menu->addOption('delete', 'Delete User'); $menu->addOption('quit', 'Quit'); // render the menu $menu->render(); // prompt the user to make a selection $selection = $menu->promptForSelection(); // do work }
输出
Options
-------
1 Add User
2 Delete User
3 Quit
Please make a selection:
> |
如果用户选择 1
,则 promptForSelection()
将返回 "add"
,2
将返回 "delete"
,3
将返回 "quit"
如果用户选择了一个不在给定选择器范围内的选项,promptForSelection()
将返回 null