From 939adfc8e207395bbea067c50311cb178bed97cc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 3 Aug 2021 14:59:18 +0200 Subject: Make necessary arrangements of new option position functionality --- bpkg/bpkg.cxx | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx index 4a4ac2d..12c44ad 100644 --- a/bpkg/bpkg.cxx +++ b/bpkg/bpkg.cxx @@ -163,7 +163,7 @@ template static O init (const common_options& co, cli::group_scanner& scan, - strings& args, + strings& args, cli::vector_scanner& args_scan, const char* cmd, bool keep_sep, bool tmp) @@ -219,6 +219,11 @@ init (const common_options& co, } } + // Carry over the positions of the arguments. In particular, this can be + // used to get the max position for the options. + // + args_scan.reset (0, scan.position ()); + // Note that the diagnostics verbosity level can only be calculated after // default options are loaded and merged (see below). Thus, to trace the // default options files search, we refer to the verbosity level specified @@ -361,7 +366,14 @@ try << system_error (errno, generic_category ()); // Sanitize. #endif - argv_file_scanner argv_scan (argc, argv, "--options-file"); + // 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); group_scanner scan (argv_scan); // First parse common options and --version/--help. @@ -379,16 +391,16 @@ try return 0; } - strings argsv; // To be filled by parse() above. - vector_scanner vect_args (argsv); - group_scanner args (vect_args); + strings argsv; // To be filled by init() above. + vector_scanner scanv (argsv); + group_scanner args (scanv); const common_options& co (o); if (o.help ()) return help (init (co, scan, - argsv, + argsv, scanv, "help", false /* keep_sep */, false /* tmp */), @@ -421,7 +433,7 @@ try { ho = init (co, scan, - argsv, + argsv, scanv, "help", false /* keep_sep */, false /* tmp */); @@ -470,6 +482,7 @@ try // r = pkg_verify (init (co, // scan, // argsv, + // scanv, // "pkg-verify", // false /* keep_sep */, // true /* tmp */), @@ -487,6 +500,7 @@ try r = NP##CMD (init (co, \ scan, \ argsv, \ + scanv, \ SP#CMD, \ SEP, \ TMP), \ -- cgit v1.1