Skip to content

Commit

Permalink
repl: completion in jq
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Sep 12, 2021
1 parent 31cd26e commit c9777aa
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 352 deletions.
16 changes: 10 additions & 6 deletions doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,19 @@ TODO: format graph?
TODO


### Known issues and useful tricks
## Known issues and useful tricks

#### Run interactive mode with no input
### Run interactive mode with no input
```sh
fq -i
null>
```

#### `.. | select(...)` fails with `expected an ... but got: ...`
### `.. | select(...)` fails with `expected an ... but got: ...`

Try add `select(...)?` to catch type errors in the select expression.

#### Manual decode
### Manual decode

Sometimes fq fails to decode or you know there is valid data buried inside some binary or maybe
you know the format of some unknown value. Then you can decode manually.
Expand All @@ -239,11 +239,11 @@ $ fq file.mp3 .unknown0._bytes[10:] mp3_frame
This won't work as expected `.a | f(.b)` as `.` is `.a` when evaluating the arguments.
Instead do `. as $c | .a | f($c.b)`.

#### Building array is slow
### Building array is slow

Try to use `map` or `foreach` to avoid rebuilding the whole array for each append.

#### Use `print` and `println` to produce more friendly compact output
### Use `print` and `println` to produce more friendly compact output

```
> [[0,"a"],[1,"b"]]
Expand All @@ -266,3 +266,7 @@ Try to use `map` or `foreach` to avoid rebuilding the whole array for each appen

`true as $verbose | repl({verbose: $verbose})` will currently fail as `repl` is
implemented by rewriting the query to `map(true as $verbose | .) | repl({verbose: $verbose})`.

### `error` produces no output

`null | error` behaves as `empty`.
2 changes: 1 addition & 1 deletion pkg/interp/args.jq
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# TODO: refactor this mess
def args_parse($args; $opts):
def _args_parse($args; $opts):
def _parse($args; $flagmap; $r):
def _parse_with_arg($new_args; $optname; $value; $opt):
if $opt.object then
Expand Down
4 changes: 2 additions & 2 deletions pkg/interp/args_test.jq
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ include "args";
string: true
}
},
expected: {
expected: {
"parsed": {
"a": "123"
},
"rest": ["b"]
}
}
][] | assert(.name; args_parse(.args; .opts); .expected)
][] | assert(.name; _args_parse(.args; .opts); .expected)
216 changes: 0 additions & 216 deletions pkg/interp/completion.go

This file was deleted.

55 changes: 0 additions & 55 deletions pkg/interp/completion_test.go

This file was deleted.

0 comments on commit c9777aa

Please sign in to comment.