11package me .itzg .helpers .files ;
22
3- import com .fasterxml .jackson .core .type .TypeReference ;
43import com .fasterxml .jackson .dataformat .toml .TomlMapper ;
54import com .jayway .jsonpath .Configuration ;
65import com .jayway .jsonpath .DocumentContext ;
76import com .jayway .jsonpath .JsonPath ;
87import com .jayway .jsonpath .ParseContext ;
98import com .jayway .jsonpath .spi .json .JacksonJsonProvider ;
10- import java .nio .file .Path ;
11- import java .util .Map ;
9+ import java .io .File ;
1210import java .util .concurrent .Callable ;
1311import picocli .CommandLine .Command ;
1412import picocli .CommandLine .ExitCode ;
13+ import picocli .CommandLine .Option ;
1514import picocli .CommandLine .Parameters ;
1615
1716@ Command (name = "toml-path" , description = "Extracts a path from a TOML file using json-path syntax" )
1817public class TomlPathCommand implements Callable <Integer > {
1918
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 ;
2221
23- @ Parameters (index = "0" , arity = "1" ,
22+ @ Parameters (arity = "1" ,
2423 paramLabel = "query" ,
2524 description = "JSON path expression where root element $ can be omitted" )
2625 String query ;
2726
28- @ Parameters (index = "1" , arity = "0..1" ,
29- paramLabel = "file" ,
30- description = "TOML file or reads stdin" )
31- Path path ;
32-
3327 @ Override
3428 public Integer call () throws Exception {
3529
@@ -40,8 +34,8 @@ public Integer call() throws Exception {
4034 );
4135
4236 final DocumentContext context ;
43- if (path != null ) {
44- context = parseContext .parse (path . toFile () );
37+ if (tomlFile != null ) {
38+ context = parseContext .parse (tomlFile );
4539 }
4640 else {
4741 context = parseContext .parse (System .in );
0 commit comments