add support for auto-generated environment variables (jsonargparse)

This commit is contained in:
Thomas Waldmann 2026-02-27 19:33:25 +01:00
parent 63a45c6c21
commit 678df16bad
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01
2 changed files with 28 additions and 0 deletions

View file

@ -284,3 +284,29 @@ Please note:
.. _INI: https://docs.python.org/3/library/logging.config.html#configuration-file-format
.. _tempfile: https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir
Automatically generated Environment Variables (jsonargparse)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Borg uses jsonargparse_ with ``default_env=True``, which means that every
command-line option can also be set via an environment variable.
The environment variable name is derived from the program name (``borg``),
the subcommand (if any), and the option name, all converted to uppercase
with dashes replaced by underscores.
For **top-level options** (not specific to a subcommand), the pattern is::
BORG_<OPTION>
For example, ``--lock-wait`` can be set via ``BORG_LOCK_WAIT``.
For **subcommand options**, the subcommand and option are separated by a
double underscore::
BORG_<SUBCOMMAND>__<OPTION>
For example, ``borg create --comment`` can be set via ``BORG_CREATE__COMMENT``.
.. _jsonargparse: https://jsonargparse.readthedocs.io/

View file

@ -251,6 +251,8 @@ class Archiver(
prog=self.prog,
description="Borg - Deduplicated Backups",
default_config_files=[os.path.join(get_config_dir(), "default.yaml")],
default_env=True,
env_prefix="BORG",
)
parser.add_argument("--config", action="config")
# paths and patterns must have an empty list as default everywhere