From 0426335af0e7577148903be7a2534c4ced06cd3b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 3 Aug 2021 14:11:17 +0200 Subject: Add support for tracking argument/option position The scanner interface now provides the position() function that returns a monotonically-increasing number which, if stored, can later be used to determine the relative position of the arguments. There is also now a parser implementation for std::pair which parses the value T into the first half of the pair and stores the option position in the second half. Together, this can be used to establish the relative position of different options, for example: class options { std::vector> --config-id; std::vector> --config-name; }; cli::argv_scanner scan (argc, argv); options ops (scan); // Iterate over --config-id and --config-name options in the order // specified by the user. // auto ii (ops.config_id ().begin ()); auto ni (ops.config_name ().begin ()); for (size_t i (0), n (scan.position ()); i != n; ++i) { if (ii != ops.config_id ().end () && ii->second == i) { // Handle *ii. ++ii; } if (ni != ops.config_name ().end () && ni->second == i) { // Handle *ni. ++ni; } } --- cli-tests/position/test.cli | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 cli-tests/position/test.cli (limited to 'cli-tests/position/test.cli') diff --git a/cli-tests/position/test.cli b/cli-tests/position/test.cli new file mode 100644 index 0000000..7fc8655 --- /dev/null +++ b/cli-tests/position/test.cli @@ -0,0 +1,13 @@ +// file : position/test.cli +// author : Boris Kolpackov +// license : MIT; see accompanying LICENSE file + +include ; +include ; +include ; + +class options +{ + std::pair -a; + std::vector > -b; +}; -- cgit v1.1