Skip to content

Commit fe8966d

Browse files
rootkiller6788abashev
authored andcommitted
Name --replace in the error for --dry-run with in-place formatting
"cannot use --dry-run and --in-place at the same time" named a flag that does not exist: in-place formatting is -i, -r, -replace or --replace (#40, from google/google-java-format#1094). The message now says --replace, the long form the usage text shows. This ports google/google-java-format#1451 by rootkiller6788, including its test for the --replace --dry-run spelling next to -i -n.
1 parent cee2533 commit fe8966d

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎open-java-format/src/main/java/com/palantir/javaformat/java/Main.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public static CommandLineOptions processArgs(String... args) throws UsageExcepti
280280
throw new UsageException("--assume-filename is only supported when formatting standard input");
281281
}
282282
if (parameters.dryRun() && parameters.inPlace()) {
283-
throw new UsageException("cannot use --dry-run and --in-place at the same time");
283+
throw new UsageException("cannot use --dry-run and --replace at the same time");
284284
}
285285
return parameters;
286286
}

‎open-java-format/src/test/java/com/palantir/javaformat/java/CommandLineFlagsTest.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,18 @@ public void inPlaceStdin() {
102102

103103
@Test
104104
public void inPlaceDryRun() {
105+
try {
106+
Main.processArgs("--replace", "--dry-run", "A.java");
107+
fail("fail");
108+
} catch (UsageException e) {
109+
assertThat(e).hasMessageThat().contains("cannot use --dry-run and --replace at the same time");
110+
}
111+
105112
try {
106113
Main.processArgs("-i", "-n", "A.java");
107114
fail("fail");
108115
} catch (UsageException e) {
109-
assertThat(e).hasMessageThat().contains("cannot use --dry-run and --in-place at the same time");
116+
assertThat(e).hasMessageThat().contains("cannot use --dry-run and --replace at the same time");
110117
}
111118
}
112119

0 commit comments

Comments
 (0)