Skip to content

Commit 219b26a

Browse files
committed
added reading and parsing for file1 and file2
1 parent 0953af9 commit 219b26a

File tree

7 files changed

+39
-11
lines changed

7 files changed

+39
-11
lines changed

app/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ build-dist:
22
./gradlew run
33

44
run-dist: build-dist
5-
/bin/sh ./build/install/app/bin/app
5+
/bin/sh ./build/install/app/bin/app -h
66

77
run:
8-
./build/install/app/bin/app
8+
./build/install/app/bin/app -h

app/app

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./build/install/app/bin/app

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies {
2424
testImplementation("org.junit.jupiter:junit-jupiter")
2525
implementation("org.apache.commons:commons-lang3:3.13.0")
2626
implementation("info.picocli:picocli:4.7.6")
27+
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.0")
2728
}
2829

2930
tasks.test {

app/src/main/java/hexlet/code/App.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import picocli.CommandLine.Command;
55
import picocli.CommandLine.Option;
66

7+
import com.fasterxml.jackson.databind.ObjectMapper;
78
import java.io.File;
8-
import java.util.List;
9+
import java.io.IOException;
10+
import java.util.Map;
911

1012

1113
@Command(name = "gendiff", mixinStandardHelpOptions = true, version = "gendiff 1.1.1",
@@ -19,7 +21,8 @@ class App implements Runnable {
1921
@Option(names = { "-V", "--version" }, versionHelp = true, description = "Print version information and exit.")
2022
boolean versionInfoRequested;
2123

22-
@Option(names = { "-f", "--format " }, paramLabel = "format", description = "output format [default: stylish]", defaultValue = "stylish")
24+
@Option(names = { "-f", "--format " }, paramLabel = "format",
25+
description = "output format [default: stylish]", defaultValue = "stylish")
2326
private String format;
2427

2528
@CommandLine.Parameters(index = "0", paramLabel = "filepath1", description = "path to first file")
@@ -30,11 +33,27 @@ class App implements Runnable {
3033

3134

3235
@Override
33-
public void run () {
34-
System.out.println("0");
36+
public void run() {
37+
try {
38+
Map<String, Object> data1 = JsonParser.readJsonFile(filepath1);
39+
Map<String, Object> data2 = JsonParser.readJsonFile(filepath2);
40+
41+
System.out.println("Файл 1: " + data1);
42+
System.out.println("Файл 2: " + data2);
43+
} catch (IOException e) {
44+
System.err.println("Ошибка при чтении файла: " + e.getMessage());
45+
}
3546
}
3647

3748
public static void main(String[] args) {
3849
new CommandLine(new App()).execute(args);
3950
}
40-
}
51+
52+
public class JsonParser {
53+
public static Map<String, Object> readJsonFile(String filePath) throws IOException {
54+
ObjectMapper objectMapper = new ObjectMapper();
55+
return objectMapper.readValue(new File("src/main/resources/" + filePath), Map.class);
56+
}
57+
}
58+
}
59+

app/src/main/java/hexlet/code/Differ.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

app/src/main/resources/file1.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"host": "hexlet.io",
3+
"timeout": 50,
4+
"proxy": "123.234.53.22",
5+
"follow": false
6+
}

app/src/main/resources/file2.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"timeout": 20,
3+
"verbose": true,
4+
"host": "hexlet.io"
5+
}

0 commit comments

Comments
 (0)