From 8b4507216ce9ac11d37bc897e1942231cf7e86c6 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Thu, 3 Sep 2026 22:47:26 +0800 Subject: [PATCH] Mention --replace instead of --in-place in the dry-run error The in-place option is spelled -i/-r/-replace/--replace on the command line; --in-place doesn't exist. The usage error for combining --dry-run with in-place formatting named a flag users never type, which made the message read like a bug. Point it at --replace (the long form listed in the help text) and add a test that triggers the error through --replace rather than only through the -i shorthand. --- .../java/com/google/googlejavaformat/java/Main.java | 2 +- .../googlejavaformat/java/CommandLineFlagsTest.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/google/googlejavaformat/java/Main.java b/core/src/main/java/com/google/googlejavaformat/java/Main.java index bfe1ff51f..23c87b799 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/Main.java +++ b/core/src/main/java/com/google/googlejavaformat/java/Main.java @@ -277,7 +277,7 @@ static CommandLineOptions processArgs(String... args) throws 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/core/src/test/java/com/google/googlejavaformat/java/CommandLineFlagsTest.java b/core/src/test/java/com/google/googlejavaformat/java/CommandLineFlagsTest.java index 928ce0078..f8777a33a 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/CommandLineFlagsTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/CommandLineFlagsTest.java @@ -150,13 +150,22 @@ public void inPlaceStdin() { @Test public void inPlaceDryRun() { + try { + Main.processArgs("--replace", "--dry-run", "A.java"); + 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(); } catch (UsageException e) { assertThat(e) .hasMessageThat() - .contains("cannot use --dry-run and --in-place at the same time"); + .contains("cannot use --dry-run and --replace at the same time"); } }