Skip to content

Commit 432d905

Browse files
authored
docs: Unify option descriptions between --help and the_basics.md (#4076)
1 parent 50e287c commit 432d905

File tree

2 files changed

+69
-51
lines changed

2 files changed

+69
-51
lines changed

docs/usage_and_configuration/the_basics.md

+24-21
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ are deliberately limited and rarely added.
3535
Note that all command-line options listed above can also be configured using a
3636
`pyproject.toml` file (more on that below).
3737

38+
#### `-h`, `--help`
39+
40+
Show available command-line options and exit.
41+
3842
#### `-c`, `--code`
3943

4044
Format the code passed in as a string.
@@ -109,6 +113,10 @@ useful when piping source on standard input.
109113
When processing Jupyter Notebooks, add the given magic to the list of known python-
110114
magics. Useful for formatting cells with custom python magics.
111115

116+
#### `-x, --skip-source-first-line`
117+
118+
Skip the first line of the source code.
119+
112120
#### `-S, --skip-string-normalization`
113121

114122
By default, _Black_ uses double quotes for all strings and normalizes string prefixes,
@@ -132,7 +140,7 @@ functionality in the next major release. Read more about
132140

133141
#### `--check`
134142

135-
Passing `--check` will make _Black_ exit with:
143+
Don't write the files back, just return the status. _Black_ will exit with:
136144

137145
- code 0 if nothing would change;
138146
- code 1 if some files would be reformatted; or
@@ -162,8 +170,8 @@ $ echo $?
162170

163171
#### `--diff`
164172

165-
Passing `--diff` will make _Black_ print out diffs that indicate what changes _Black_
166-
would've made. They are printed to stdout so capturing them is simple.
173+
Don't write the files back, just output a diff to indicate what changes _Black_ would've
174+
made. They are printed to stdout so capturing them is simple.
167175

168176
If you'd like colored diffs, you can enable them with `--color`.
169177

@@ -179,6 +187,10 @@ All done! ✨ 🍰 ✨
179187
1 file would be reformatted.
180188
```
181189

190+
#### `--color` / `--no-color`
191+
192+
Show (or do not show) colored diff. Only applies when `--diff` is given.
193+
182194
### `--line-ranges`
183195

184196
When specified, _Black_ will try its best to only format these lines.
@@ -202,10 +214,6 @@ extra lines outside of the ranges when ther are unformatted lines with the exact
202214
content. It also disables _Black_'s formatting stability check in `--safe` mode.
203215
```
204216

205-
#### `--color` / `--no-color`
206-
207-
Show (or do not show) colored diff. Only applies when `--diff` is given.
208-
209217
#### `--fast` / `--safe`
210218

211219
By default, _Black_ performs [an AST safety check](labels/ast-changes) after formatting
@@ -256,7 +264,7 @@ instead of overriding them.
256264
#### `--force-exclude`
257265

258266
Like `--exclude`, but files and directories matching this regex will be excluded even
259-
when they are passed explicitly as arguments. This is useful when invoking _Black_
267+
when they are passed explicitly as arguments. This is useful when invoking Black
260268
programmatically on changed files, such as in a pre-commit hook or editor plugin.
261269

262270
#### `--stdin-filename`
@@ -275,12 +283,12 @@ exclusions, including from `.gitignore` and command line options.
275283

276284
When _Black_ formats multiple files, it may use a process pool to speed up formatting.
277285
This option controls the number of parallel workers. This can also be specified via the
278-
`BLACK_NUM_WORKERS` environment variable.
286+
`BLACK_NUM_WORKERS` environment variable. Defaults to the number of CPUs in the system.
279287

280288
#### `-q`, `--quiet`
281289

282-
Passing `-q` / `--quiet` will cause _Black_ to stop emitting all non-critical output.
283-
Error messages will still be emitted (which can silenced by `2>/dev/null`).
290+
Stop emitting all non-critical output. Error messages will still be emitted (which can
291+
silenced by `2>/dev/null`).
284292

285293
```console
286294
$ black src/ -q
@@ -289,9 +297,9 @@ error: cannot format src/black_primer/cli.py: Cannot parse: 5:6: mport asyncio
289297

290298
#### `-v`, `--verbose`
291299

292-
Passing `-v` / `--verbose` will cause _Black_ to also emit messages about files that
293-
were not changed or were ignored due to exclusion patterns. If _Black_ is using a
294-
configuration file, a blue message detailing which one it is using will be emitted.
300+
Emit messages about files that were not changed or were ignored due to exclusion
301+
patterns. If _Black_ is using a configuration file, a message detailing which one it is
302+
using will be emitted.
295303

296304
```console
297305
$ black src/ -v
@@ -321,10 +329,6 @@ black, 23.11.0
321329
Read configuration options from a configuration file. See
322330
[below](#configuration-via-a-file) for more details on the configuration file.
323331

324-
#### `-h`, `--help`
325-
326-
Show available command-line options and exit.
327-
328332
### Environment variable options
329333

330334
_Black_ supports the following configuration via environment variables.
@@ -355,7 +359,7 @@ All done! ✨ 🍰 ✨
355359
use `--stdin-filename`. Useful to make sure _Black_ will respect the `--force-exclude`
356360
option on some editors that rely on using stdin.
357361

358-
You can also pass code as a string using the `-c` / `--code` option.
362+
You can also pass code as a string using the `--code` option.
359363

360364
### Writeback and reporting
361365

@@ -435,8 +439,7 @@ refers to the path to your home directory. On Windows, this will be something li
435439
You can also explicitly specify the path to a particular file that you want with
436440
`--config`. In this situation _Black_ will not look for any other file.
437441

438-
If you're running with `--verbose`, you will see a blue message if a file was found and
439-
used.
442+
If you're running with `--verbose`, you will see a message if a file was found and used.
440443

441444
Please note `blackd` will not use `pyproject.toml` configuration.
442445

src/black/__init__.py

+45-30
Original file line numberDiff line numberDiff line change
@@ -235,25 +235,26 @@ def validate_regex(
235235
callback=target_version_option_callback,
236236
multiple=True,
237237
help=(
238-
"Python versions that should be supported by Black's output. By default, Black"
239-
" will try to infer this from the project metadata in pyproject.toml. If this"
240-
" does not yield conclusive results, Black will use per-file auto-detection."
238+
"Python versions that should be supported by Black's output. You should"
239+
" include all versions that your code supports. By default, Black will infer"
240+
" target versions from the project metadata in pyproject.toml. If this does"
241+
" not yield conclusive results, Black will use per-file auto-detection."
241242
),
242243
)
243244
@click.option(
244245
"--pyi",
245246
is_flag=True,
246247
help=(
247-
"Format all input files like typing stubs regardless of file extension (useful"
248-
" when piping source on standard input)."
248+
"Format all input files like typing stubs regardless of file extension. This"
249+
" is useful when piping source on standard input."
249250
),
250251
)
251252
@click.option(
252253
"--ipynb",
253254
is_flag=True,
254255
help=(
255-
"Format all input files like Jupyter Notebooks regardless of file extension "
256-
"(useful when piping source on standard input)."
256+
"Format all input files like Jupyter Notebooks regardless of file extension."
257+
"This is useful when piping source on standard input."
257258
),
258259
)
259260
@click.option(
@@ -310,38 +311,47 @@ def validate_regex(
310311
@click.option(
311312
"--diff",
312313
is_flag=True,
313-
help="Don't write the files back, just output a diff for each file on stdout.",
314+
help=(
315+
"Don't write the files back, just output a diff to indicate what changes"
316+
" Black would've made. They are printed to stdout so capturing them is simple."
317+
),
318+
)
319+
@click.option(
320+
"--color/--no-color",
321+
is_flag=True,
322+
help="Show (or do not show) colored diff. Only applies when --diff is given.",
314323
)
315324
@click.option(
316325
"--line-ranges",
317326
multiple=True,
318327
metavar="START-END",
319328
help=(
320-
"When specified, _Black_ will try its best to only format these lines. This"
329+
"When specified, Black will try its best to only format these lines. This"
321330
" option can be specified multiple times, and a union of the lines will be"
322331
" formatted. Each range must be specified as two integers connected by a `-`:"
323332
" `<START>-<END>`. The `<START>` and `<END>` integer indices are 1-based and"
324333
" inclusive on both ends."
325334
),
326335
default=(),
327336
)
328-
@click.option(
329-
"--color/--no-color",
330-
is_flag=True,
331-
help="Show colored diff. Only applies when `--diff` is given.",
332-
)
333337
@click.option(
334338
"--fast/--safe",
335339
is_flag=True,
336-
help="If --fast given, skip temporary sanity checks. [default: --safe]",
340+
help=(
341+
"By default, Black performs an AST safety check after formatting your code."
342+
" The --fast flag turns off this check and the --safe flag explicitly enables"
343+
" it. [default: --safe]"
344+
),
337345
)
338346
@click.option(
339347
"--required-version",
340348
type=str,
341349
help=(
342-
"Require a specific version of Black to be running (useful for unifying results"
343-
" across many environments e.g. with a pyproject.toml file). It can be"
344-
" either a major version number or an exact version."
350+
"Require a specific version of Black to be running. This is useful for"
351+
" ensuring that all contributors to your project are using the same"
352+
" version, because different versions of Black may format code a little"
353+
" differently. This option can be set in a configuration file for consistent"
354+
" results across environments."
345355
),
346356
)
347357
@click.option(
@@ -371,18 +381,20 @@ def validate_regex(
371381
type=str,
372382
callback=validate_regex,
373383
help=(
374-
"Like --exclude, but files and directories matching this regex will be "
375-
"excluded even when they are passed explicitly as arguments."
384+
"Like --exclude, but files and directories matching this regex will be excluded"
385+
" even when they are passed explicitly as arguments. This is useful when"
386+
" invoking Black programmatically on changed files, such as in a pre-commit"
387+
" hook or editor plugin."
376388
),
377389
)
378390
@click.option(
379391
"--stdin-filename",
380392
type=str,
381393
is_eager=True,
382394
help=(
383-
"The name of the file when passing it through stdin. Useful to make "
384-
"sure Black will respect --force-exclude option on some "
385-
"editors that rely on using stdin."
395+
"The name of the file when passing it through stdin. Useful to make sure Black"
396+
" will respect the --force-exclude option on some editors that rely on using"
397+
" stdin."
386398
),
387399
)
388400
@click.option(
@@ -405,26 +417,29 @@ def validate_regex(
405417
type=click.IntRange(min=1),
406418
default=None,
407419
help=(
408-
"Number of parallel workers [default: BLACK_NUM_WORKERS environment variable "
409-
"or number of CPUs in the system]"
420+
"When Black formats multiple files, it may use a process pool to speed up"
421+
" formatting. This option controls the number of parallel workers. This can"
422+
" also be specified via the BLACK_NUM_WORKERS environment variable. Defaults"
423+
" to the number of CPUs in the system."
410424
),
411425
)
412426
@click.option(
413427
"-q",
414428
"--quiet",
415429
is_flag=True,
416430
help=(
417-
"Don't emit non-error messages to stderr. Errors are still emitted; silence"
418-
" those with 2>/dev/null."
431+
"Stop emitting all non-critical output. Error messages will still be emitted"
432+
" (which can silenced by 2>/dev/null)."
419433
),
420434
)
421435
@click.option(
422436
"-v",
423437
"--verbose",
424438
is_flag=True,
425439
help=(
426-
"Also emit messages to stderr about files that were not changed or were ignored"
427-
" due to exclusion patterns."
440+
"Emit messages about files that were not changed or were ignored due to"
441+
" exclusion patterns. If Black is using a configuration file, a message"
442+
" detailing which one it is using will be emitted."
428443
),
429444
)
430445
@click.version_option(
@@ -455,7 +470,7 @@ def validate_regex(
455470
),
456471
is_eager=True,
457472
callback=read_pyproject_toml,
458-
help="Read configuration from FILE path.",
473+
help="Read configuration options from a configuration file.",
459474
)
460475
@click.pass_context
461476
def main( # noqa: C901

0 commit comments

Comments
 (0)