Skip to content

Commit 61dd4de

Browse files
authored
toml-path: match usage of yaml-path (#527)
1 parent f1b4985 commit 61dd4de

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/main/java/me/itzg/helpers/files/TomlPathCommand.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
11
package me.itzg.helpers.files;
22

3-
import com.fasterxml.jackson.core.type.TypeReference;
43
import com.fasterxml.jackson.dataformat.toml.TomlMapper;
54
import com.jayway.jsonpath.Configuration;
65
import com.jayway.jsonpath.DocumentContext;
76
import com.jayway.jsonpath.JsonPath;
87
import com.jayway.jsonpath.ParseContext;
98
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
10-
import java.nio.file.Path;
11-
import java.util.Map;
9+
import java.io.File;
1210
import java.util.concurrent.Callable;
1311
import picocli.CommandLine.Command;
1412
import picocli.CommandLine.ExitCode;
13+
import picocli.CommandLine.Option;
1514
import picocli.CommandLine.Parameters;
1615

1716
@Command(name = "toml-path", description = "Extracts a path from a TOML file using json-path syntax")
1817
public 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);

src/test/java/me/itzg/helpers/files/TomlPathCommandTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package me.itzg.helpers.files;
22

3-
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOut;
3+
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOutNormalized;
44
import static org.assertj.core.api.Assertions.assertThat;
55

66
import java.nio.file.Paths;
@@ -14,11 +14,11 @@ class TomlPathCommandTest {
1414
@ParameterizedTest
1515
@ValueSource(strings = {"$.bind", ".bind"})
1616
void extractsVelocityBind(String queryPath) throws Exception {
17-
final String out = tapSystemOut(() -> {
17+
final String out = tapSystemOutNormalized(() -> {
1818
final int exitCode = new CommandLine(new TomlPathCommand())
1919
.execute(
20-
queryPath,
21-
Paths.get("src/test/resources/velocity.toml").toString()
20+
"--file", Paths.get("src/test/resources/velocity.toml").toString(),
21+
queryPath
2222
);
2323

2424
assertThat(exitCode).isEqualTo(ExitCode.OK);

0 commit comments

Comments
 (0)