Skip to content

Commit 03fc2e1

Browse files
kdeldyckegithub-actions[bot]
authored andcommitted
[autofix] Format Markdown
1 parent 2198253 commit 03fc2e1

File tree

10 files changed

+254
-94
lines changed

10 files changed

+254
-94
lines changed

docs/commands.md

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Click Extra aims to be a drop-in replacement for Click. The vast majority of Cli
77
Here is for instance the [canonical `click` example](https://github.com/pallets/click#a-simple-example) with all original imports replaced with `click_extra`:
88

99
```{click:example}
10-
:emphasize-lines: 1
10+
---
11+
emphasize-lines: 1
12+
---
1113
from click_extra import command, echo, option
1214
1315
@command
@@ -110,7 +112,9 @@ The `@extra_command` and `@extra_group` decorators are [pre-configured with a se
110112
You can remove all default options by resetting the `params` argument to `None`:
111113

112114
```{click:example}
113-
:emphasize-lines: 3
115+
---
116+
emphasize-lines: 3
117+
---
114118
from click_extra import extra_command
115119
116120
@extra_command(params=None)
@@ -140,7 +144,9 @@ As you can see, all options are stripped out, but the colouring and formatting o
140144
To override the default options, you can provide the `params=` argument to the command. But note how we use classes instead of option decorators:
141145

142146
```{click:example}
143-
:emphasize-lines: 4-7
147+
---
148+
emphasize-lines: 4-7
149+
---
144150
from click_extra import extra_command, ConfigOption, VerbosityOption
145151
146152
@extra_command(
@@ -156,7 +162,9 @@ def cli():
156162
And now you get:
157163

158164
```{click:run}
159-
:emphasize-lines: 5-9
165+
---
166+
emphasize-lines: 5-9
167+
---
160168
from textwrap import dedent
161169
result = invoke(cli, args=["--help"])
162170
assert result.stdout.startswith(dedent(
@@ -171,7 +179,9 @@ assert result.stdout.startswith(dedent(
171179
This let you replace the preset options by your own set, tweak their order and fine-tune their defaults.
172180

173181
````{admonition} Duplicate options
174-
:class: caution
182+
---
183+
class: caution
184+
---
175185
If you try to add option decorators to a command which already have them by default, you will end up with duplicate entries ([as seen in issue #232](https://github.com/kdeldycke/click-extra/issues/232)):
176186
177187
```{click:example}
@@ -221,7 +231,9 @@ For example, the [`--verbosity` option defaults to the `WARNING` level](logging.
221231
If you manage your own `--verbosity` option, you can [pass the `default` argument to its decorator like we did above](#change-default-options):
222232

223233
```{click:example}
224-
:emphasize-lines: 4
234+
---
235+
emphasize-lines: 4
236+
---
225237
from click_extra import command, verbosity_option
226238
227239
@command
@@ -233,7 +245,9 @@ def cli():
233245
This also works in its class form:
234246

235247
```{click:example}
236-
:emphasize-lines: 3
248+
---
249+
emphasize-lines: 3
250+
---
237251
from click_extra import command, VerbosityOption
238252
239253
@command(params=[VerbosityOption(default="INFO")])
@@ -244,7 +258,9 @@ def cli():
244258
But you also have the alternative to pass a `default_map` via the `context_settings`:
245259

246260
```{click:example}
247-
:emphasize-lines: 3
261+
---
262+
emphasize-lines: 3
263+
---
248264
from click_extra import extra_command
249265
250266
@extra_command(context_settings={"default_map": {"verbosity": "INFO"}})
@@ -255,7 +271,9 @@ def cli():
255271
Which results in `[default: INFO]` being featured in the help message:
256272

257273
```{click:run}
258-
:emphasize-lines: 17
274+
---
275+
emphasize-lines: 17
276+
---
259277
result = invoke(cli, args=["--help"])
260278
assert "\x1b[2m[\x1b[0m\x1b[2mdefault: \x1b[0m\x1b[32m\x1b[2m\x1b[3mINFO\x1b[0m\x1b[2m]\x1b[0m\n" in result.stdout
261279
```
@@ -355,7 +373,9 @@ if __name__ == "__main__":
355373
And this simple script gets rendered into:
356374

357375
```{code-block} shell-session
358-
:emphasize-lines: 22-23
376+
---
377+
emphasize-lines: 22-23
378+
---
359379
$ uv run -- python ./wrap.py
360380
Usage: wrap.py [OPTIONS] COMMAND [ARGS]...
361381
@@ -522,7 +542,9 @@ Examples:
522542
Here is the highlighted differences to make them even more obvious:
523543

524544
```{code-block} diff
525-
:emphasize-lines: 2-5,13-14
545+
---
546+
emphasize-lines: 2-5,13-14
547+
---
526548
@@ -1,5 +1,5 @@
527549
-$ uv run -- python ./wrap.py aws_sam --help
528550
-Usage: wrap.py aws_sam [OPTIONS] COMMAND [ARGS]...

docs/config.md

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ data structure to mirror the CLI.
99
The `@config_option` decorator provided by Click Extra can be used as-is with vanilla Click:
1010

1111
```{click:example}
12-
:emphasize-lines: 7
12+
---
13+
emphasize-lines: 7
14+
---
1315
from click import group, option, echo
1416
from click_extra import config_option
1517
@@ -32,7 +34,9 @@ The code above is saved into a file named `my_cli.py`.
3234
It produces the following help screen:
3335

3436
```{click:run}
35-
:emphasize-lines: 7-10
37+
---
38+
emphasize-lines: 7-10
39+
---
3640
result = invoke(my_cli, args=["--help"])
3741
assert "-C, --config CONFIG_PATH" in result.stdout
3842
```
@@ -107,7 +111,9 @@ The parameter will take the first value set in that chain.
107111
See how inline parameters takes priority on defaults from the previous example:
108112

109113
```{code-block} shell-session
110-
:emphasize-lines: 1, 4
114+
---
115+
emphasize-lines: 1, 4
116+
---
111117
$ my-cli subcommand --int-param 555
112118
dummy_flag is True
113119
my_list is ('item 1', 'item #2', 'Very Last Item!')
@@ -121,7 +127,9 @@ After gathering all the configuration from the different sources, and assembling
121127
You can still access the full configuration by looking into the context's `meta` attribute:
122128

123129
```{code-block} python
124-
:emphasize-lines: 9-12
130+
---
131+
emphasize-lines: 9-12
132+
---
125133
from click_extra import option, echo, pass_context, command, config_option
126134
127135
@@ -147,7 +155,9 @@ dummy_flag = true
147155
```
148156

149157
```{code-block} shell-session
150-
:emphasize-lines: 3-6
158+
---
159+
emphasize-lines: 3-6
160+
---
151161
$ my-cli --config ./conf.toml --int-param 999
152162
Load configuration matching ./conf.toml
153163
Configuration location: /home/me/conf.toml
@@ -181,7 +191,9 @@ random_param = "forbidden"
181191
The use of `strict=True` parameter in the CLI below:
182192

183193
```{code-block} python
184-
:emphasize-lines: 7
194+
---
195+
emphasize-lines: 7
196+
---
185197
from click import command, option, echo
186198
187199
from click_extra import config_option
@@ -196,7 +208,9 @@ def cli(int_param):
196208
Will raise an error and stop the CLI execution on unrecognized `random_param` value:
197209

198210
```{code-block} shell-session
199-
:emphasize-lines: 4
211+
---
212+
emphasize-lines: 4
213+
---
200214
$ cli --config "cli.toml"
201215
Load configuration matching cli.toml
202216
(...)
@@ -212,7 +226,9 @@ It {py:attr}`defaults to the value of ParamStructure.DEFAULT_EXCLUDED_PARAMS <cl
212226
You can set your own list of option to ignore with the `excluded_params` argument:
213227

214228
```{code-block} python
215-
:emphasize-lines: 7
229+
---
230+
emphasize-lines: 7
231+
---
216232
from click import command, option, echo
217233
218234
from click_extra import config_option
@@ -274,7 +290,9 @@ garbage: >
274290
```
275291

276292
```{code-block} shell-session
277-
:emphasize-lines: 2-4
293+
---
294+
emphasize-lines: 2-4
295+
---
278296
$ my-cli --config "~/.config/my-cli/config.yaml" subcommand
279297
dummy_flag is True
280298
my_list is ('point 1', 'point #2', 'Very Last Point!')
@@ -308,7 +326,9 @@ Again, same for JSON:
308326
```
309327

310328
```{code-block} shell-session
311-
:emphasize-lines: 2-4
329+
---
330+
emphasize-lines: 2-4
331+
---
312332
$ my-cli --config "~/.config/my-cli/config.json" subcommand
313333
dummy_flag is True
314334
my_list is ('item 1', 'item #2', 'Very Last Item!')
@@ -367,7 +387,9 @@ Like the latter, the `@config_option` decorator and `ConfigOption` class accept
367387
Let's change the default base folder in the following example:
368388

369389
```{click:example}
370-
:emphasize-lines: 6
390+
---
391+
emphasize-lines: 6
392+
---
371393
from click import command
372394
373395
from click_extra import config_option
@@ -381,7 +403,9 @@ def cli():
381403
See how the default to `--config` option has been changed to `~/.cli/*.{toml,yaml,yml,json,ini,xml}`:
382404

383405
```{click:run}
384-
:emphasize-lines: 7
406+
---
407+
emphasize-lines: 7
408+
---
385409
result = invoke(cli, args=["--help"])
386410
assert "~/.cli/*.{toml,yaml,yml,json,ini,xml}]" in result.stdout
387411
```
@@ -393,7 +417,9 @@ If you'd like to customize the pattern, you can pass your own to the `default` p
393417
Here is how to look for an extension-less YAML dotfile in the home directory, with a pre-defined `.commandrc` name:
394418

395419
```{click:example}
396-
:emphasize-lines: 7
420+
---
421+
emphasize-lines: 7
422+
---
397423
from click import command
398424
399425
from click_extra import config_option
@@ -406,7 +432,9 @@ def cli():
406432
```
407433

408434
```{click:run}
409-
:emphasize-lines: 7
435+
---
436+
emphasize-lines: 7
437+
---
410438
result = invoke(cli, args=["--help"])
411439
assert "~/.commandrc]" in result.stdout
412440
```
@@ -452,7 +480,9 @@ As soon as a file is able to be parsed without error and returns a `dict`, the s
452480
If you know in advance the only format you'd like to support, you can use the `formats` argument on your decorator like so:
453481

454482
```{click:example}
455-
:emphasize-lines: 8
483+
---
484+
emphasize-lines: 8
485+
---
456486
from click import command, option, echo
457487
458488
from click_extra import config_option
@@ -468,15 +498,19 @@ def cli(int_param):
468498
Notice how the default search pattern gets limited to files with a `.json` extension:
469499

470500
```{click:run}
471-
:emphasize-lines: 8
501+
---
502+
emphasize-lines: 8
503+
---
472504
result = invoke(cli, args=["--help"])
473505
assert "*.json]" in result.stdout
474506
```
475507

476508
This also works with a subset of formats:
477509

478510
```{click:example}
479-
:emphasize-lines: 8
511+
---
512+
emphasize-lines: 8
513+
---
480514
from click import command, option, echo
481515
482516
from click_extra import config_option
@@ -490,7 +524,9 @@ def cli(int_param):
490524
```
491525

492526
```{click:run}
493-
:emphasize-lines: 8
527+
---
528+
emphasize-lines: 8
529+
---
494530
result = invoke(cli, args=["--help"])
495531
assert "*.{ini,yaml,yml}]" in result.stdout
496532
```
@@ -500,7 +536,9 @@ assert "*.{ini,yaml,yml}]" in result.stdout
500536
Remote URL can be passed directly to the `--config` option:
501537

502538
```{code-block} shell-session
503-
:emphasize-lines: 1
539+
---
540+
emphasize-lines: 1
541+
---
504542
$ my-cli --config "https://example.com/dummy/configuration.yaml" subcommand
505543
dummy_flag is True
506544
my_list is ('point 1', 'point #2', 'Very Last Point!')

0 commit comments

Comments
 (0)