Skip to content

Commit bb4db2c

Browse files
Factor out filter hooks for better usability. Improve documentation in README
1 parent 35235e8 commit bb4db2c

File tree

11 files changed

+405
-248
lines changed

11 files changed

+405
-248
lines changed

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@ This project uses [dflydev/dot-access-data](https://github.com/dflydev/dot-acces
1212

1313
This project provides a simple logic expression evaluator which can be used in conjunction with [dflydev/dot-access-data](https://github.com/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.
1414

15+
### API
16+
17+
To use this filter in your annotated-commands-aware application (see [g1a/starter](https://github.com/g1a/starter)), ensure that the filter hooks are registered with
18+
```
19+
$commandClasses = [
20+
\Consolidation\Filter\Hooks\FilterHooks::class, // Filter hooks
21+
\MyApp\Commands\MyCommands::class, // Commandfiles for your application
22+
];
23+
$runner = new \Robo\Runner($commandClasses);
24+
```
25+
Then, any command that returns RowsOfFields data (see [consolidation/output-formatters](https://github.com/consolidation/output-formatters)) or an array may utilize the output filter feature simply by annotating its command method with `@filter-output`.
26+
```
27+
/**
28+
* Convert a command from one format to another, potentially with filtering.
29+
*
30+
* @command example
31+
* @filter-output
32+
* @return array
33+
*/
34+
public function example(array $parameters, $options = ['format' => 'yaml'])
35+
{
36+
return $this->doSomething($parameters);
37+
}
38+
```
39+
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:
40+
```
41+
$ mycmd example p1 p2 --filter='color=red'
42+
```
43+
The filter decides whether to include or exclude each **top-level element** based on the result of evaluating the provided expression on each element.
44+
45+
- Nested data elements may be tested, e.g. via `attributes.color=red`
46+
- Simple boolean logic may be used, e.g. `color=red&shape=round`
47+
48+
Parenthesis are not supported.
49+
1550
### Commandline Tool
1651

1752
This project is bundled with a simple commandline tool, `dot-process`. It is similar to a simple version of `jq`. It is intended for demonstration purposes only.

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.2.0-dev

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@cs"
5252
],
5353
"release": [
54-
"( echo && echo 'Ensure that VERSION file contains the version to release.' && echo \"Current version: $(cat VERSION)\" && tag=$(cat VERSION) && git tag \"$tag\" && git push origin \"$tag\" )"
54+
"release VERSION"
5555
],
5656
"scenario": "scenarios/install",
5757
"post-update-cmd": [

0 commit comments

Comments
 (0)