@@ -43,6 +43,9 @@ called ``addon_player_damage`` which defaults to 64:
4343 # Write the configuration file out to the folder.
4444 addon_config.write()
4545
46+ # Execute the configuration file.
47+ addon_config.execute()
48+
4649 And here is the resulting addon.cfg file:
4750
4851.. code-block :: none
@@ -108,6 +111,9 @@ called ``Description``:
108111 # remain unchanged.
109112 addon_config.write()
110113
114+ # Execute the configuration file.
115+ addon_config.execute()
116+
111117 Which results in the following configuration file:
112118
113119.. code-block :: none
@@ -190,6 +196,9 @@ character to use in order to create the section boundaries:
190196 # remain unchanged.
191197 addon_config.write()
192198
199+ # Execute the configuration file.
200+ addon_config.execute()
201+
193202 This generates the following configuration file:
194203
195204.. code-block :: none
@@ -213,3 +222,38 @@ This generates the following configuration file:
213222 // Default Value: models/player.mdl
214223 // Model to set on the player.
215224 addon_player_model "models/player.mdl"
225+
226+
227+ Using context management
228+ ------------------------
229+
230+ All of the above examples show explicitly calling the :meth: `config.manager.ConfigManager.write `
231+ and :meth: `config.manager.ConfigManager.execute ` methods. You can also
232+ automatically call these by using context management:
233+
234+ .. code-block :: python
235+
236+ # =============================================================================
237+ # >> IMPORTS
238+ # =============================================================================
239+ # Source.Python Imports
240+ # Config
241+ from config.manager import ConfigManager
242+ # Cvars
243+ from cvars.flags import ConVarFlags
244+
245+ # Create the configuration file.
246+ # Using 'with' will utilize the __enter__ and __exit__ methods to
247+ # automatically write and execute the configuration file.
248+ with ConfigManager(' addon' ) as addon_config:
249+
250+ # Modify the header of the entire configuration file.
251+ addon_config.header = ' Addon configuration file.'
252+
253+ # Create a console variable to add to the configuration file.
254+ addon_player_damage = addon_config.cvar(
255+ ' addon_player_damage' , ' 64' ,
256+ ' How much damage to cause to each player.' , ConVarFlags.CHEAT
257+ )
258+
259+ For reference: :mod: `contextlib `
0 commit comments