Skip to content

Commit ea88c0f

Browse files
authored
refactor: cli file communitcation (#825)
1 parent 16ba5e9 commit ea88c0f

File tree

25 files changed

+1345
-44
lines changed

25 files changed

+1345
-44
lines changed

cli/flamingock-cli-executor/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ plugins {
55

66
description = "Flamingock CLI for executing changes in applications"
77

8+
val jacksonVersion = "2.16.0"
9+
810
dependencies {
911
// CLI Framework
1012
implementation("info.picocli:picocli:4.7.5")
1113
annotationProcessor("info.picocli:picocli-codegen:4.7.5")
1214

15+
// Core dependencies for response handling
16+
implementation(project(":core:flamingock-core-commons"))
17+
implementation(project(":utils:general-util"))
18+
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
19+
1320
// Test dependencies
1421
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
1522
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.2")

cli/flamingock-cli-executor/src/main/java/io/flamingock/cli/executor/FlamingockExecutorCli.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.flamingock.cli.executor;
1717

18+
import io.flamingock.cli.executor.command.AuditCommand;
1819
import io.flamingock.cli.executor.command.ExecuteCommand;
1920
import io.flamingock.cli.executor.handler.ExecutorExceptionHandler;
2021
import io.flamingock.cli.executor.util.VersionProvider;
@@ -41,11 +42,12 @@
4142
"",
4243
"@|bold Examples:|@",
4344
" flamingock execute apply --jar ./app.jar",
45+
" flamingock audit list --jar ./app.jar",
4446
" flamingock --verbose execute apply --jar ./my-app.jar",
4547
"",
4648
"For detailed help on any command, use: flamingock <command> --help"
4749
},
48-
subcommands = {ExecuteCommand.class},
50+
subcommands = {ExecuteCommand.class, AuditCommand.class},
4951
mixinStandardHelpOptions = true,
5052
versionProvider = VersionProvider.class
5153
)

cli/flamingock-cli-executor/src/main/java/io/flamingock/cli/executor/command/ApplyCommand.java

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@
1818
import io.flamingock.cli.executor.FlamingockExecutorCli;
1919
import io.flamingock.cli.executor.output.ConsoleFormatter;
2020
import io.flamingock.cli.executor.process.JvmLauncher;
21+
import io.flamingock.cli.executor.result.ResponseResultReader;
22+
import io.flamingock.cli.executor.result.ResponseResultReader.ResponseResult;
2123
import io.flamingock.cli.executor.util.VersionProvider;
24+
import io.flamingock.internal.common.core.response.data.ExecuteResponseData;
2225
import picocli.CommandLine;
2326
import picocli.CommandLine.Command;
2427
import picocli.CommandLine.Option;
2528
import picocli.CommandLine.ParentCommand;
2629

2730
import java.io.File;
31+
import java.io.IOException;
32+
import java.nio.file.Files;
33+
import java.nio.file.Path;
2834
import java.util.concurrent.Callable;
2935

3036
/**
@@ -54,6 +60,11 @@ public class ApplyCommand implements Callable<Integer> {
5460
*/
5561
public static final int EXIT_JAR_NOT_FOUND = 126;
5662

63+
/**
64+
* Operation string for EXECUTE operation (matches FlamingockArguments parsing).
65+
*/
66+
private static final String OPERATION_EXECUTE = "EXECUTE";
67+
5768
@ParentCommand
5869
private ExecuteCommand parent;
5970

@@ -87,20 +98,55 @@ public Integer call() {
8798
ConsoleFormatter.printVerbose("JAR file: " + jarFile.getAbsolutePath(), verbose);
8899
ConsoleFormatter.printInfo("Launching Flamingock execution...");
89100

90-
// Launch the Spring Boot application with CLI mode enabled
91-
JvmLauncher launcher = new JvmLauncher(verbose);
92-
int exitCode = launcher.launch(jarFile.getAbsolutePath());
101+
Path outputFile = null;
102+
try {
103+
outputFile = Files.createTempFile("flamingock-response-", ".json");
104+
ConsoleFormatter.printVerbose("Response file: " + outputFile, verbose);
105+
106+
JvmLauncher launcher = new JvmLauncher(verbose);
107+
int exitCode = launcher.launch(jarFile.getAbsolutePath(), OPERATION_EXECUTE, outputFile.toString());
108+
109+
if (exitCode == 0 && Files.exists(outputFile)) {
110+
ResponseResultReader reader = new ResponseResultReader();
111+
ResponseResult<ExecuteResponseData> result = reader.readTyped(outputFile, ExecuteResponseData.class);
112+
113+
if (result.isSuccess()) {
114+
if (!quiet) {
115+
ConsoleFormatter.printSuccess();
116+
if (result.getData() != null && result.getData().getMessage() != null) {
117+
ConsoleFormatter.printInfo(result.getData().getMessage());
118+
}
119+
ConsoleFormatter.printInfo("Duration: " + result.getDurationMs() + "ms");
120+
}
121+
} else {
122+
ConsoleFormatter.printError("Error: " + result.getErrorMessage());
123+
return 1;
124+
}
125+
} else if (exitCode != 0) {
126+
if (Files.exists(outputFile)) {
127+
ResponseResultReader reader = new ResponseResultReader();
128+
ResponseResult<ExecuteResponseData> result = reader.readTyped(outputFile, ExecuteResponseData.class);
129+
if (!result.isSuccess()) {
130+
ConsoleFormatter.printError("Error [" + result.getErrorCode() + "]: " + result.getErrorMessage());
131+
}
132+
}
133+
ConsoleFormatter.printFailure();
134+
return exitCode;
135+
}
93136

94-
// Print result message
95-
if (exitCode == 0) {
96-
if (!quiet) {
97-
ConsoleFormatter.printSuccess();
137+
return 0;
138+
139+
} catch (IOException e) {
140+
ConsoleFormatter.printError("Failed to create temporary file: " + e.getMessage());
141+
return 1;
142+
} finally {
143+
if (outputFile != null) {
144+
try {
145+
Files.deleteIfExists(outputFile);
146+
} catch (IOException ignored) {
147+
}
98148
}
99-
} else {
100-
ConsoleFormatter.printFailure();
101149
}
102-
103-
return exitCode;
104150
}
105151

106152
private FlamingockExecutorCli getRootCommand() {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2025 Flamingock (https://www.flamingock.io)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.flamingock.cli.executor.command;
17+
18+
import picocli.CommandLine;
19+
import picocli.CommandLine.Command;
20+
21+
/**
22+
* Parent command for audit operations.
23+
*
24+
* <p>Groups subcommands related to audit inspection:</p>
25+
* <ul>
26+
* <li>{@code list} - List audit entries</li>
27+
* </ul>
28+
*/
29+
@Command(
30+
name = "audit",
31+
description = "Audit operations for inspecting change history",
32+
subcommands = {ListCommand.class},
33+
mixinStandardHelpOptions = true
34+
)
35+
public class AuditCommand implements Runnable {
36+
37+
@CommandLine.ParentCommand
38+
private Object parent;
39+
40+
@Override
41+
public void run() {
42+
// Show help when no subcommand is specified
43+
new CommandLine(this).usage(System.out);
44+
}
45+
}

0 commit comments

Comments
 (0)