You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,41 @@ This project uses [dflydev/dot-access-data](https://github.com/dflydev/dot-acces
12
12
13
13
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.
14
14
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
\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
+
15
50
### Commandline Tool
16
51
17
52
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.
0 commit comments