hanneskod/comphlete
Composer 安装命令:
composer require hanneskod/comphlete
包简介
Dynamic bash completion from PHP
关键字:
README 文档
README
Dynamic bash completion from PHP
Why?
Say you have a cli script to read some data, using comphlete you can autocomplete data identifiers directly from the command line. It's both fun and powerful. And works well with symfony console apps.
Installation
composer require hanneskod/comphlete
Usage
With symfony apps
Create an empty symfony console application (here named myapp.php).
$application = new \Symfony\Component\Console\Application(); $application->add(new \hanneskod\comphlete\Symfony\ComphleteCommand); $application->run();
This creates a hidden command named _complete that handles autocompletion.
To register autocompletion in your enviroment use (in .bashrc)
source $(myapp.php _complete --generate-bash-script --app-name=myapp.php)
NOTE that the
ComphleteCommanddoes not work for single command applications. If your application is a single command app you'll have to revert to the default way of createing suggestions. See below.
The (not so) hard way
Create your autocomplete definition in a php script (here named test.php).
namespace hanneskod\comphlete; $definition = (new Definition) // first argument with a fixed set of suggestions ->addArgument(0, ['foo', 'bar', 'baz']) // second argument with a dynamic callback ->addArgument(1, function () { // load suggestions from database... return ['aa', 'bb']; }) // simple option ->addOption('foo') // option with suggested values ->addOption('bar', ['val1', 'val2']) ; $completer = new Completer($definition); $input = (new InputFactory)->createFromArgv($argv); echo Helper::dump($completer->complete($input));
To load into you environment create a bash script (note that this requires
test.php to be in you PATH to work properly).
php bash_load_script_template.php test.php > load.sh
And source it (in .bashrc)
source load.sh
Using contexts
A common design pattern is to have an application define a number of commands
with their own sets of arguments and options. Comphlete supports this by the use
of contexts. Here is an app with an import and an export command.
$import = (new ContextDefinition('import')) ->addArgument(1, ['some-argument']) ; $export = (new ContextDefinition('export')) ->addArgument(1, ['another-argument']) ; $def = (new ContextContainerDefinition) ->addContext($import) ->addContext($export) ; $completer = new Completer($def); $input = (new InputFactory)->createFromArgv($argv); echo Helper::dump($completer->complete($input));
hanneskod/comphlete 适用场景与选型建议
hanneskod/comphlete 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 127 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「autocomplete」 「complete」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hanneskod/comphlete 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hanneskod/comphlete 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hanneskod/comphlete 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An auto-completing Laravel Nova search field.
The Cassandra php driver library IDE stubs which enables autocompletion in modern IDEs.
Provides Twig template IDE autocomplete of Craft CMS & plugin variables
A PHP package to determine steps and progress.
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
Gets the complete thought from a verb and a noun using Moby Thesaurus
统计信息
- 总下载量: 127
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unlicense
- 更新时间: 2019-09-10