1
1
package me .itzg .helpers .files ;
2
2
3
- import com .fasterxml .jackson .core .type .TypeReference ;
4
3
import com .fasterxml .jackson .dataformat .toml .TomlMapper ;
5
4
import com .jayway .jsonpath .Configuration ;
6
5
import com .jayway .jsonpath .DocumentContext ;
7
6
import com .jayway .jsonpath .JsonPath ;
8
7
import com .jayway .jsonpath .ParseContext ;
9
8
import com .jayway .jsonpath .spi .json .JacksonJsonProvider ;
10
- import java .nio .file .Path ;
11
- import java .util .Map ;
9
+ import java .io .File ;
12
10
import java .util .concurrent .Callable ;
13
11
import picocli .CommandLine .Command ;
14
12
import picocli .CommandLine .ExitCode ;
13
+ import picocli .CommandLine .Option ;
15
14
import picocli .CommandLine .Parameters ;
16
15
17
16
@ Command (name = "toml-path" , description = "Extracts a path from a TOML file using json-path syntax" )
18
17
public class TomlPathCommand implements Callable <Integer > {
19
18
20
- public static final TypeReference < Map < String , Object >> MAP_TYPE = new TypeReference < Map < String , Object >>() {
21
- } ;
19
+ @ Option ( names = "--file" , paramLabel = "FILE" , description = "A TOML file to query. If not set, reads stdin" )
20
+ File tomlFile ;
22
21
23
- @ Parameters (index = "0" , arity = "1" ,
22
+ @ Parameters (arity = "1" ,
24
23
paramLabel = "query" ,
25
24
description = "JSON path expression where root element $ can be omitted" )
26
25
String query ;
27
26
28
- @ Parameters (index = "1" , arity = "0..1" ,
29
- paramLabel = "file" ,
30
- description = "TOML file or reads stdin" )
31
- Path path ;
32
-
33
27
@ Override
34
28
public Integer call () throws Exception {
35
29
@@ -40,8 +34,8 @@ public Integer call() throws Exception {
40
34
);
41
35
42
36
final DocumentContext context ;
43
- if (path != null ) {
44
- context = parseContext .parse (path . toFile () );
37
+ if (tomlFile != null ) {
38
+ context = parseContext .parse (tomlFile );
45
39
}
46
40
else {
47
41
context = parseContext .parse (System .in );
0 commit comments