@@ -16,6 +16,10 @@ to, and channels to join. By default, it creates the file
1616Once this is done, the ``start `` subcommand runs the bot, using this
1717configuration file unless one is provided using the ``-c ``/``--config `` option.
1818
19+ Certain command-line options can be passed via environment variables. Also see
20+ the :ref: `section on environment variables <Supported environment variables >`
21+ for more possibilities.
22+
1923.. contents ::
2024 :local:
2125 :depth: 1
@@ -67,3 +71,80 @@ The ``sopel-plugins`` command
6771
6872.. autoprogram :: sopel.cli.plugins:build_parser()
6973 :prog: sopel-plugins
74+
75+
76+ Supported environment variables
77+ ===============================
78+
79+
80+ ``SOPEL_CONFIG ``
81+ ----------------
82+
83+ This environment variable replaces the built-in default config name (which is,
84+ confusingly, also "default") if set. It's interpreted in the same way as the
85+ ``-c ``/``--config `` option accepted by most CLI commands described above.
86+
87+ .. versionadded :: 7.0
88+
89+
90+ ``SOPEL_CONFIG_DIR ``
91+ --------------------
92+
93+ This environment variable replaces the default directory in which Sopel
94+ searches for config files. It's interpreted in the same way as the
95+ ``--config-dir `` option accepted by most CLI commands described above.
96+
97+ .. versionadded :: 7.1
98+
99+
100+ Overriding individual settings
101+ ------------------------------
102+
103+ Whenever a setting is accessed, Sopel looks for a matching environment
104+ variable. If found, the environment variable's value (even if it's empty)
105+ overrides the value from Sopel's config file.
106+
107+ The variable name Sopel looks for is structured as follows:
108+
109+ * ``SOPEL_ `` prefix (to prevent collisions with other programs)
110+ * The section name in UPPERCASE, e.g. ``CORE `` or ``PLUGIN_NAME ``
111+ * ``_ `` as separator
112+ * The setting name in UPPERCASE, e.g. ``NICK `` or ``API_KEY ``
113+
114+ For example, take this stripped-down config file:
115+
116+ .. code-block :: ini
117+
118+ [core]
119+ nick = ConfigFileNick
120+ host = chat.freenode.net
121+
122+ [plugin_name]
123+ api_key = abad1dea
124+
125+ Sopel would take the nickname ``ConfigFileNick `` when connecting to IRC at
126+ ``chat.freenode.net ``, and the ``plugin_name `` plugin would use the API key
127+ ``abad1dea `` when communicating with its remote service.
128+
129+ However, by setting the environment variables:
130+
131+ .. code-block :: shell
132+
133+ SOPEL_CORE_NICK=EnvVarNick
134+ SOPEL_PLUGIN_NAME_API_KEY=1337c0ffee9001
135+
136+ Sopel would take the nickname ``EnvVarNick `` when connecting to IRC (still at
137+ ``chat.freenode.net ``; that value isn't overridden or lost), and the
138+ ``plugin_name `` plugin would use the API key ``1337c0ffee9001 ``, instead.
139+
140+ .. versionadded :: 7.0
141+
142+ .. note ::
143+
144+ Any ``_ `` character in the section or setting name also appears in the
145+ environment variable name. It's therefore *theoretically * possible for two
146+ plugins to have section and setting name pairs that both resolve to the same
147+ environment variable name, but in practice this is highly unlikely.
148+
149+ However, should such a collision occur, please notify the main Sopel project
150+ *and * both plugin authors via any relevant communication channel(s).
0 commit comments