mirror of
https://github.com/wader/fq.git
synced 2024-12-23 13:22:58 +03:00
repl: Make prompt for array and iter more jqish
Really need to refactor script.go some day into a proper parser
This commit is contained in:
parent
ece2fd78ec
commit
9770b0046b
@ -425,7 +425,7 @@ func ParseCases(s string) *Case {
|
||||
|
||||
// TODO: better section splitter, too much heuristics now
|
||||
for _, section := range SectionParser(regexp.MustCompile(
|
||||
`^\$ .*$|^stdin:$|^stderr:$|^exitcode:.*$|^#.*$|^/.*:|^[^<:|]+>.*$`,
|
||||
`^\$ .*$|^stdin:$|^stderr:$|^exitcode:.*$|^#.*$|^/.*:|^[^<|"]+>.*$`,
|
||||
), s) {
|
||||
n, v := section.Name, section.Value
|
||||
|
||||
|
@ -124,7 +124,7 @@ def _prompt:
|
||||
)
|
||||
end
|
||||
, "]"
|
||||
, if length > 1 then "[\(length)]" else empty end
|
||||
, if length > 1 then "[0:\(length)]" else empty end
|
||||
] | join("")
|
||||
else
|
||||
( . as $c
|
||||
@ -146,7 +146,7 @@ def _prompt:
|
||||
if length == 0 then "empty"
|
||||
else
|
||||
[ (.[0] | _value)
|
||||
, if length > 1 then ", ...[\(length)]" else empty end
|
||||
, if length > 1 then ", ...[0:\(length)][]" else empty end
|
||||
] | join("")
|
||||
end;
|
||||
[ _repl_level
|
||||
|
8
pkg/interp/testdata/inputs.fqtest
vendored
8
pkg/interp/testdata/inputs.fqtest
vendored
@ -82,14 +82,14 @@ exitcode: 4
|
||||
stderr:
|
||||
error: /a: probe: failed to decode (try -d FORMAT)
|
||||
$ fq -i -d raw . /a /b /c
|
||||
raw, ...[3]> ._format
|
||||
raw, ...[0:3][]> ._format
|
||||
"raw"
|
||||
"raw"
|
||||
"raw"
|
||||
raw, ...[3]> ^D
|
||||
raw, ...[0:3][]> ^D
|
||||
$ fq -i -s -d raw . /a /b /c
|
||||
[raw, ...][3]> .[]._format
|
||||
[raw, ...][0:3]> .[]._format
|
||||
"raw"
|
||||
"raw"
|
||||
"raw"
|
||||
[raw, ...][3]> ^D
|
||||
[raw, ...][0:3]> ^D
|
||||
|
26
pkg/interp/testdata/repl.fqtest
vendored
26
pkg/interp/testdata/repl.fqtest
vendored
@ -19,26 +19,26 @@ null> 1 | 2 | repl
|
||||
3
|
||||
> number> ^D
|
||||
null> 1,2,3 | repl
|
||||
> number, ...[3]> .
|
||||
> number, ...[0:3][]> .
|
||||
1
|
||||
2
|
||||
3
|
||||
> number, ...[3]> ^D
|
||||
> number, ...[0:3][]> ^D
|
||||
null> (1 | raw | .unknown0), 1 | repl
|
||||
> .unknown0 string, ...[2]> ^D
|
||||
> .unknown0 string, ...[0:2][]> ^D
|
||||
null> def f: 1; f,f | repl
|
||||
> number, ...[2]> .
|
||||
> number, ...[0:2][]> .
|
||||
1
|
||||
1
|
||||
> number, ...[2]> ^D
|
||||
> number, ...[0:2][]> ^D
|
||||
null> [1,2,3] | repl
|
||||
> [number, ...][3]> .
|
||||
> [number, ...][0:3]> .
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
> [number, ...][3]> ^D
|
||||
> [number, ...][0:3]> ^D
|
||||
null> [1] | repl
|
||||
> [number]> .
|
||||
[
|
||||
@ -52,17 +52,17 @@ $ fq -i 'empty'
|
||||
empty> 1
|
||||
empty> ^D
|
||||
$ fq -i 1,2,3
|
||||
number, ...[3]> .*2
|
||||
number, ...[0:3][]> .*2
|
||||
2
|
||||
4
|
||||
6
|
||||
number, ...[3]> ^D
|
||||
number, ...[0:3][]> ^D
|
||||
$ fq -i '[1,2,3]'
|
||||
[number, ...][3]> repl({compact: true})
|
||||
> [number, ...][3]> tovalue
|
||||
[number, ...][0:3]> repl({compact: true})
|
||||
> [number, ...][0:3]> tovalue
|
||||
[1,2,3]
|
||||
> [number, ...][3]> ^D
|
||||
[number, ...][3]> ^D
|
||||
> [number, ...][0:3]> ^D
|
||||
[number, ...][0:3]> ^D
|
||||
$ fq -i -d mp3 '.headers[0]' /test.mp3
|
||||
.headers[0] id3v2> ^D
|
||||
$ fq -i -d mp3 . /test.mp3
|
||||
|
Loading…
Reference in New Issue
Block a user