consolidation / filter-via-dot-access-data
This project uses dflydev/dot-access-data to provide simple output filtering for applications built with annotated-command / Robo.
Requires
- php: >=7.1.3
- dflydev/dot-access-data: ^1.1.0 || ^2.0.0 || ^3.0.0
Requires (Dev)
- phpunit/phpunit: ^7.5.20 || ^8 || ^9
- squizlabs/php_codesniffer: ^3
- yoast/phpunit-polyfills: ^0.2.0
This package is auto-updated.
Last update: 2024-10-29 05:40:29 UTC
README
This project uses dflydev/dot-access-data to provide simple output filtering for applications built with annotated-command / Robo.
Overview
This project provides a simple logic expression evaluator which can be used in conjunction with dflydev/dot-access-data to filter out results of the sort that you might return as a RowsOfFields object, or a nested yaml/json array.
API
To use this filter in your annotated-commands-aware application (see g1a/starter), ensure that the filter hooks are registered with
$commandClasses = [
\Consolidation\Filter\Hooks\FilterHooks::class, // Filter hooks
\MyApp\Commands\MyCommands::class, // Commandfiles for your application
];
$runner = new \Robo\Runner($commandClasses);
Then, any command that returns RowsOfFields data (see consolidation/output-formatters) or an array may utilize the output filter feature simply by annotating its command method with @filter-output
.
/**
* Convert a command from one format to another, potentially with filtering.
*
* @command example
* @filter-output
* @return array
*/
public function example(array $parameters, $options = ['format' => 'yaml'])
{
return $this->doSomething($parameters);
}
Annotating a command in this way will automaitically attach a --filter[=FILTER]
option to the command. The output of the command may then be filtered by providing a simple expression:
$ mycmd example p1 p2 --filter='color=red'
A contains
comparison may be done via the *=
operator:
$ mycmd example p1 p2 --filter='color*=red'
And, finally, regex compares are also available via ~=
:
$ mycmd example p1 p2 --filter='color~=#^red.*#'
The filter decides whether to include or exclude each top-level element based on the result of evaluating the provided expression on each element.
- Nested data elements may be tested, e.g. via
attributes.color=red
- Simple boolean logic may be used, e.g.
color=red&&shape=round
Parenthesis are not supported.
Getting Started
To build this project locally, follow the steps below.
Prerequisites
Install dependencies:
composer install
If you wish to build the phar for this project, install the box
phar builder via:
composer phar:install-tools
Running the tests
The test suite may be run locally by way of some simple composer scripts:
Deployment
Deploy by the following procedure:
- Edit the
VERSION
file to contain the version to release, and commit the change. - Run
composer release
Contributing
Please read CONTRIBUTING.md for details on the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the releases page.
Authors
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details