@@ -10,9 +10,11 @@ that use configuration files.
10
10
.. _click : https://click.pocoo.org/
11
11
12
12
13
- EXAMPLE::
13
+ EXAMPLE:
14
14
15
- # -- FILE: *.py
15
+ .. code-block :: python
16
+
17
+ # -- FILE: example_command_with_configfile.py (PART 1)
16
18
# BASIC SOLUTION FOR: Command that uses one or more configuration files.
17
19
import click
18
20
@@ -40,9 +42,11 @@ before the command-line parsing begins.
40
42
In addition, there should be a simple way to specify the configuration schema
41
43
in the configuration file in a similar way like the command-line options.
42
44
An example how this functionality may look like, is shown in the following
43
- code snippet::
45
+ code snippet:
46
+
47
+ .. code-block :: python
44
48
45
- # -- FILE: * .py
49
+ # -- FILE: example_command_with_configfile .py (PART 2)
46
50
# Description of sections in a confguration file: *.ini
47
51
from click_configfile import matches_section, Param, SectionSchema
48
52
@@ -72,6 +76,8 @@ The example shows that the ``Param`` class supports similar arguments like a
72
76
73
77
An example for a valid configuration file with this schema is::
74
78
79
+ .. code-block :: ini
80
+
75
81
# -- FILE: foo.ini
76
82
[foo]
77
83
flag = yes # -- SUPPORTS: true, false, yes, no (case-insensitive)
@@ -90,9 +96,11 @@ An example for a valid configuration file with this schema is::
90
96
91
97
92
98
The following code snippet shows the remaing core implementation of reading
93
- the configuration file (and parsing the configuration file data)::
99
+ the configuration file (and parsing the configuration file data):
100
+
101
+ .. code-block :: python
94
102
95
- # -- FILE: * .py
103
+ # -- FILE: example_command_with_configfile .py (PART 3)
96
104
import configparser # HINT: Use backport for Python2
97
105
from click_configparser import generate_configfile_names, \
98
106
select_config_sections, parse_config_section
@@ -148,10 +156,11 @@ the configuration file (and parsing the configuration file data)::
148
156
The source code snippet above already contains a large number of generic
149
157
functionality. Most of it can be avoided for processing a specific
150
158
configuration file by using the ``ConfigFileReader `` class.
159
+ The resulting source code is:
151
160
152
- The resulting source code is::
161
+ .. code-block :: python
153
162
154
- # -- FILE: hello_command .py
163
+ # -- FILE: example_command_with_configfile .py (ALL PARTS: simplified)
155
164
from click_configfile import ConfigFileReader, Param, SectionSchema
156
165
from click_configfile import matches_section
157
166
import click
0 commit comments