aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-08-05 19:43:48 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-08-06 11:00:17 +0300
commita3d021860053687e9244b86df244cd13c096ee39 (patch)
treeeb0b4436ed07ab72fbb7708d6576d8f80346e96b
parent4fa713a22e1634c82e67bb78219524839b3c2997 (diff)
Adapt to support for option positions added to butl::load_default_options()
-rw-r--r--bpkg/bpkg.cxx32
1 files changed, 23 insertions, 9 deletions
diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx
index 0fc1dbe..9488509 100644
--- a/bpkg/bpkg.cxx
+++ b/bpkg/bpkg.cxx
@@ -5,6 +5,7 @@
# include <signal.h> // signal()
#endif
+#include <limits>
#include <iostream>
#include <exception> // set_terminate(), terminate_handler
#include <type_traits> // enable_if, is_base_of
@@ -154,6 +155,20 @@ cfg_dir (const O* o) -> decltype(o->directory ()) {return o->directory ();}
static inline auto
cfg_dir (...) -> const dir_path& {return empty_dir_path;}
+// Command line arguments starting position.
+//
+// We want the positions of the command line arguments to be after the default
+// options files (parsed in init()). Normally that would be achieved by
+// passing the last position of the previous scanner to the next. The problem
+// is that we parse the command line arguments first (for good reasons). Also
+// the default options files parsing machinery needs the maximum number of
+// arguments to be specified and assigns the positions below this value (see
+// load_default_options() for details). So we are going to "reserve" the first
+// half of the size_t value range for the default options positions and the
+// second half for the command line arguments positions.
+//
+static const size_t args_pos (numeric_limits<size_t>::max () / 2);
+
// Initialize the command option class O with the common options and then
// parse the rest of the command line placing non-option arguments to args.
// Once this is done, use the "final" values of the common options to do
@@ -272,9 +287,15 @@ init (const common_options& co,
trace << "loading " << (r ? "remote " : "local ") << f;
}
},
- "--options-file"),
+ "--options-file",
+ args_pos,
+ 1024),
o);
}
+ catch (const invalid_argument& e)
+ {
+ fail << "unable to load default options files: " << e;
+ }
catch (const pair<path, system_error>& e)
{
fail << "unable to load default options files: " << e.first << ": "
@@ -366,14 +387,7 @@ try
<< system_error (errno, generic_category ()); // Sanitize.
#endif
- // We want the positions of the command line arguments to be after the
- // default options files (parsed in init()). Normally that would be achieved
- // by passing the last position of the previous scanner to the next. The
- // problem is that we parse the command line arguments first (for good
- // reasons). So as a somewhat hackish work around, we are going to "reserve"
- // 256 positions for the default options files.
- //
- argv_file_scanner argv_scan (argc, argv, "--options-file", false, 256);
+ argv_file_scanner argv_scan (argc, argv, "--options-file", false, args_pos);
group_scanner scan (argv_scan);
// First parse common options and --version/--help.