aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpkg/bpkg.cli6
-rw-r--r--bpkg/bpkg.cxx24
2 files changed, 27 insertions, 3 deletions
diff --git a/bpkg/bpkg.cli b/bpkg/bpkg.cli
index 4975db7..48f655e 100644
--- a/bpkg/bpkg.cli
+++ b/bpkg/bpkg.cli
@@ -336,5 +336,11 @@ namespace bpkg
Recoverable error which is likely to disappear if the command is
re-executed.||
+
+ \h|ENVIRONMENT|
+
+ The \cb{BPKG_DEF_OPT} environment variable is used to suppress loading of
+ default options files in nested \cb{bpkg} invocations. Its values are
+ \cb{false} or \cb{0} to suppress and \cb{true} or \cb{1} to load.
"
}
diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx
index 7aba553..7c1847d 100644
--- a/bpkg/bpkg.cxx
+++ b/bpkg/bpkg.cxx
@@ -166,6 +166,9 @@ init (const common_options& co,
bool keep_sep,
bool tmp)
{
+ using bpkg::optional;
+ using bpkg::getenv;
+
tracer trace ("init");
O o;
@@ -226,14 +229,23 @@ init (const common_options& co,
: o.V () ? 3 : o.v () ? 2 : o.quiet () ? 0 : 1;
};
- // Handle default options files.
+ // Load the default options files, unless --no-default-options is specified
+ // on the command line or the BPKG_DEF_OPT environment variable is set to a
+ // value other than 'true' or '1'.
+ //
+ optional<string> env_def (getenv ("BPKG_DEF_OPT"));
+
+ // False if --no-default-options is specified on the command line. Note that
+ // we cache the flag since it can be overridden by a default options file.
//
+ bool cmd_def (!o.no_default_options ());
+
// Note: don't need to use group_scaner (no arguments in options files).
//
- if (!o.no_default_options ()) // Command line option.
+ if (cmd_def && (!env_def || *env_def == "true" || *env_def == "1"))
try
{
- bpkg::optional<dir_path> extra;
+ optional<dir_path> extra;
if (o.default_options_specified ())
extra = o.default_options ();
@@ -265,6 +277,12 @@ init (const common_options& co,
fail << "unable to obtain home directory: " << e;
}
+ // Propagate disabling of the default options files to the potential nested
+ // invocations.
+ //
+ if (!cmd_def && (!env_def || *env_def != "0"))
+ setenv ("BPKG_DEF_OPT", "0");
+
// Global initializations.
//