Skip to content

Commit e4e484f

Browse files
add support for auto-generated environment variables (jsonargparse)
1 parent fb6ce2d commit e4e484f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

docs/usage/general/environment.rst.inc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,29 @@ Please note:
284284
.. _INI: https://docs.python.org/3/library/logging.config.html#configuration-file-format
285285
286286
.. _tempfile: https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir
287+
288+
289+
Automatically generated Environment Variables (jsonargparse)
290+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291+
292+
Borg uses jsonargparse_ with ``default_env=True``, which means that every
293+
command-line option can also be set via an environment variable.
294+
295+
The environment variable name is derived from the program name (``borg``),
296+
the subcommand (if any), and the option name, all converted to uppercase
297+
with dashes replaced by underscores.
298+
299+
For **top-level options** (not specific to a subcommand), the pattern is::
300+
301+
BORG_<OPTION>
302+
303+
For example, ``--lock-wait`` can be set via ``BORG_LOCK_WAIT``.
304+
305+
For **subcommand options**, the subcommand and option are separated by a
306+
double underscore::
307+
308+
BORG_<SUBCOMMAND>__<OPTION>
309+
310+
For example, ``borg create --comment`` can be set via ``BORG_CREATE__COMMENT``.
311+
312+
.. _jsonargparse: https://jsonargparse.readthedocs.io/

src/borg/archiver/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ def build_parser(self):
251251
prog=self.prog,
252252
description="Borg - Deduplicated Backups",
253253
default_config_files=[os.path.join(get_config_dir(), "default.yaml")],
254+
default_env=True,
254255
)
255256
parser.add_argument("--config", action="config")
256257
# paths and patterns must have an empty list as default everywhere

0 commit comments

Comments
 (0)