Skip to content

Commit aaa6ffc

Browse files
committed
docs: improve docs
1 parent d2f57b2 commit aaa6ffc

File tree

3 files changed

+56
-20
lines changed

3 files changed

+56
-20
lines changed

README.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,24 @@ Usage: spotless [-hV] [-e=<encoding>] [-l=<lineEnding>] [--log-file=<logFile>]
115115
[FORMATTING_STEPS]
116116
Runs spotless
117117
-e, --encoding=<encoding> The encoding of the files to format.
118-
(default: UTF-8)
118+
(default: UTF-8)
119119
-h, --help Show this help message and exit.
120120
-l, --line-ending=<lineEnding>
121121
The line ending of the files to format.
122-
One of: GIT_ATTRIBUTES,
122+
One of: GIT_ATTRIBUTES,
123123
GIT_ATTRIBUTES_FAST_ALLSAME, PLATFORM_NATIVE,
124124
WINDOWS, UNIX, MAC_CLASSIC, PRESERVE
125-
(default: UNIX)
125+
(default: UNIX)
126126
--log-file=<logFile> The log file to write the output to.
127127
-m, --mode=<spotlessMode> The mode to run spotless in.
128-
One of: CHECK, APPLY
129-
(default: APPLY)
128+
One of: CHECK, APPLY
129+
(default: APPLY)
130+
APPLY: Apply the correct formatting where needed
131+
(replace file contents with formatted content).
132+
CHECK: Check if the files are formatted or show
133+
the diff of the formatting.
130134
-p, --parallelity=N The number of parallel formatter threads to run.
131-
(default: #cores * 0.5)
135+
(default: #cores * 0.5)
132136
-q, --quiet Disable as much output as possible.
133137
-t, --target=<targets> The target files to format.
134138
-v Enable verbose output. Multiple -v options
@@ -139,6 +143,19 @@ Available formatting steps:
139143
license-header Runs license header
140144
google-java-format Runs google java format
141145
prettier Runs prettier, the opinionated code formatter.
146+
147+
Possible exit codes:
148+
0 Successful formatting.
149+
In APPLY mode, this means all files were formatted.
150+
In CHECK mode, this means all files are already formatted properly.
151+
1 Some files need formatting.
152+
In APPLY mode, this means some files failed to be formatted (see output
153+
for details).
154+
In CHECK mode, this means some files are not formatted properly (and
155+
might be fixed in APPLY mode).
156+
-1 Some files did not converge. This can happen in APPLY mode when the
157+
formatter does not converge on the file content.
158+
-2 An exception occurred during execution.
142159
```
143160

144161
<!---freshmark /usage_main -->
@@ -179,15 +196,15 @@ Usage: spotless google-java-format [-hijrV] [-s=<style>]
179196
Runs google java format
180197
-h, --help Show this help message and exit.
181198
-i, --reorder-imports Reorder imports.
182-
(default: false)
199+
(default: false)
183200
-j, --format-javadoc Format javadoc.
184-
(default: true)
201+
(default: true)
185202
-r, --reflow-long-strings
186203
Reflow long strings.
187-
(default: false)
204+
(default: false)
188205
-s, --style=<style> The style to use for the google java format.
189-
One of: AOSP, GOOGLE
190-
(default: GOOGLE)
206+
One of: AOSP, GOOGLE
207+
(default: GOOGLE)
191208
-V, --version Print version information and exit.
192209
```
193210

@@ -237,16 +254,16 @@ Runs license header
237254
-m, --year-mode=<yearMode>
238255
How and if the year in the copyright header should be
239256
updated.
240-
One of: PRESERVE, UPDATE_TO_TODAY, SET_FROM_GIT
241-
(default: PRESERVE)
257+
One of: PRESERVE, UPDATE_TO_TODAY, SET_FROM_GIT
258+
(default: PRESERVE)
242259
-s, --skip-lines-matching=<skipLinesMatching>
243260
Skip lines matching the given regex pattern before
244261
inserting the licence header.
245262
-V, --version Print version information and exit.
246263
-Y, --year-separator=<yearSeparator>
247264
The separator to use for the year range in the
248265
license header.
249-
(default: -)
266+
(default: -)
250267
```
251268

252269
<!---freshmark /usage_license_header -->
@@ -295,15 +312,15 @@ Runs prettier, the opinionated code formatter.
295312
Additional locations to search for .npmrc files.
296313
-c, --prettier-config-option='OPTION=VALUE'
297314
A prettier configuration options.
298-
The format is 'OPTION=VALUE'.
299-
example: 'printWidth=80'
315+
The format is 'OPTION=VALUE'.
316+
example: 'printWidth=80'
300317
-C, --npm-install-cache-dir=<npmInstallCacheDir>
301318
The directory to use for caching libraries retrieved by 'npm
302319
install'.
303320
-D, --dev-dependency='PACKAGE=VERSION'
304321
An entry to add to the package.json for running prettier.
305-
The format is 'PACKAGE=VERSION'.
306-
example: 'prettier=2.8.7'
322+
The format is 'PACKAGE=VERSION'.
323+
example: 'prettier=2.8.7'
307324
-h, --help Show this help message and exit.
308325
-n, --npm-exec=<explicitNpmExecutable>
309326
The explicit path to the npm executable.

app/src/main/java/com/diffplug/spotless/cli/SpotlessCLI.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@
6666
""",
6767
synopsisSubcommandLabel = "[FORMATTING_STEPS]",
6868
commandListHeading = "%nAvailable formatting steps:%n",
69+
exitCodeListHeading = "%nPossible exit codes:%n",
70+
exitCodeOnExecutionException = -2,
71+
exitCodeList = {
72+
"""
73+
0:Successful formatting.
74+
In @|yellow APPLY|@ mode, this means all files were formatted.
75+
In @|yellow CHECK|@ mode, this means all files are already formatted properly.""",
76+
"""
77+
1:Some files need formatting.
78+
In @|yellow APPLY|@ mode, this means some files failed to be formatted (see output for details).
79+
In @|yellow CHECK|@ mode, this means some files are not formatted properly (and might be fixed in APPLY mode).""",
80+
"-1:Some files did not converge. This can happen when one formatter does not converge on the file content.",
81+
"-2:An exception occurred during execution."
82+
},
6983
subcommandsRepeatable = true,
7084
subcommands = {LicenseHeader.class, GoogleJavaFormat.class, Prettier.class})
7185
public class SpotlessCLI implements SpotlessAction, SpotlessCommand, SpotlessActionContextProvider {
@@ -78,7 +92,12 @@ public class SpotlessCLI implements SpotlessAction, SpotlessCommand, SpotlessAct
7892
@CommandLine.Option(
7993
names = {"--mode", "-m"},
8094
defaultValue = "APPLY",
81-
description = "The mode to run spotless in." + OptionConstants.VALID_AND_DEFAULT_VALUES_SUFFIX)
95+
description =
96+
"The mode to run spotless in." + OptionConstants.VALID_AND_DEFAULT_VALUES_SUFFIX
97+
+ OptionConstants.NEW_LINE
98+
+ """
99+
APPLY: Apply the correct formatting where needed (replace file contents with formatted content).
100+
CHECK: Check if the files are formatted or show the diff of the formatting.""")
82101
SpotlessMode spotlessMode;
83102

84103
@CommandLine.Option(

app/src/main/java/com/diffplug/spotless/cli/help/OptionConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
public final class OptionConstants {
1919

20-
public static final String NEW_LINE = "%n ";
20+
public static final String NEW_LINE = "%n";
2121

2222
public static final String VALID_VALUES_SUFFIX = NEW_LINE + "One of: ${COMPLETION-CANDIDATES}";
2323

0 commit comments

Comments
 (0)