From c73a0830bae8a7144ae03c0e9c26a9ea58c9a326 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Wed, 23 Sep 2026 10:45:38 +0300 Subject: [PATCH] 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. --- .../src/main/java/com/palantir/javaformat/java/Main.java | 2 +- .../palantir/javaformat/java/CommandLineFlagsTest.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/Main.java b/open-java-format/src/main/java/com/palantir/javaformat/java/Main.java index a05188668..48c533435 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/Main.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/Main.java @@ -273,7 +273,7 @@ public static CommandLineOptions processArgs(String... args) throws UsageExcepti throw new UsageException("--assume-filename is only supported when formatting standard input"); } if (parameters.dryRun() && parameters.inPlace()) { - throw new UsageException("cannot use --dry-run and --in-place at the same time"); + throw new UsageException("cannot use --dry-run and --replace at the same time"); } return parameters; } diff --git a/open-java-format/src/test/java/com/palantir/javaformat/java/CommandLineFlagsTest.java b/open-java-format/src/test/java/com/palantir/javaformat/java/CommandLineFlagsTest.java index 7ce5ee956..2dea6c882 100644 --- a/open-java-format/src/test/java/com/palantir/javaformat/java/CommandLineFlagsTest.java +++ b/open-java-format/src/test/java/com/palantir/javaformat/java/CommandLineFlagsTest.java @@ -102,11 +102,18 @@ public void inPlaceStdin() { @Test public void inPlaceDryRun() { + try { + Main.processArgs("--replace", "--dry-run", "A.java"); + fail("fail"); + } catch (UsageException e) { + assertThat(e).hasMessageThat().contains("cannot use --dry-run and --replace at the same time"); + } + try { Main.processArgs("-i", "-n", "A.java"); fail("fail"); } catch (UsageException e) { - assertThat(e).hasMessageThat().contains("cannot use --dry-run and --in-place at the same time"); + assertThat(e).hasMessageThat().contains("cannot use --dry-run and --replace at the same time"); } }