Skip to content

Commit

Permalink
Factor out filter hooks for better usability. Improve documentation i…
Browse files Browse the repository at this point in the history
…n README
  • Loading branch information
greg-1-anderson committed Oct 3, 2018
1 parent 35235e8 commit bb4db2c
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 248 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,41 @@ This project uses [dflydev/dot-access-data](https://github.com/dflydev/dot-acces

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.

### API

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
```
$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](https://github.com/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'
```
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.

### Commandline Tool

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.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0-dev
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@cs"
],
"release": [
"( 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\" )"
"release VERSION"
],
"scenario": "scenarios/install",
"post-update-cmd": [
Expand Down

0 comments on commit bb4db2c

Please sign in to comment.