Skip to content

Commit 7b0e1f5

Browse files
authored
Merge pull request #38 from quen2404/feature/cli-state
Return only diff state in cli
2 parents 84d893b + 3b8cf68 commit 7b0e1f5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ usage: openapi-diff <old> <new>
4747
output in file
4848
--off No information printed
4949
--query <property=value> use query param for authorisation
50+
--state Only output diff state: no_changes,
51+
incompatible, compatible
5052
--trace be extra verbose
5153
--version print the version information and exit
5254
--warn Print warning information

src/main/java/com/qdesrame/openapi/diff/Main.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static void main(String... args) {
2323
Options options = new Options();
2424
options.addOption(Option.builder("h").longOpt("help").desc("print this message").build());
2525
options.addOption(Option.builder().longOpt("version").desc("print the version information and exit").build());
26+
options.addOption(Option.builder().longOpt("state").desc("Only output diff state: no_changes, incompatible, compatible").build());
2627
options.addOption(Option.builder().longOpt("trace").desc("be extra verbose").build());
2728
options.addOption(Option.builder().longOpt("debug").desc("Print debugging information").build());
2829
options.addOption(Option.builder().longOpt("info").desc("Print additional information").build());
@@ -81,6 +82,9 @@ public static void main(String... args) {
8182
logLevel));
8283
}
8384
}
85+
if (line.hasOption("state")) {
86+
logLevel = "OFF";
87+
}
8488
LogManager.getRootLogger().setLevel(Level.toLevel(logLevel));
8589

8690
if (line.getArgList().size() < 2) {
@@ -126,7 +130,12 @@ public static void main(String... args) {
126130
System.exit(2);
127131
}
128132
}
129-
System.exit(result.isDiff() ? 1 : 0);
133+
if (line.hasOption("state")) {
134+
System.out.println(result.isDiff() ? result.isDiffBackwardCompatible() ? "compatible" : "incompatible" : "no_changes");
135+
System.exit(0);
136+
} else {
137+
System.exit(result.isDiff() ? 1 : 0);
138+
}
130139
} catch (ParseException e) {
131140
// oops, something went wrong
132141
System.err.println("Parsing failed. Reason: " + e.getMessage());

0 commit comments

Comments
 (0)