From a3d021860053687e9244b86df244cd13c096ee39 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 5 Aug 2021 19:43:48 +0300 Subject: Adapt to support for option positions added to butl::load_default_options() --- bpkg/bpkg.cxx | 32 +++++++++++++++++++++++--------- 1 file 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() #endif +#include #include #include // set_terminate(), terminate_handler #include // 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::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& 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. -- cgit v1.1