summaryrefslogtreecommitdiff
path: root/cli-tests/position/test.cli
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-08-03 14:11:17 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-08-03 14:11:17 +0200
commit0426335af0e7577148903be7a2534c4ced06cd3b (patch)
tree9d7d1de01c9e438097cfd9d235f4df3206761b54 /cli-tests/position/test.cli
parenta54c695583015812280228bcadca3057397d4dd0 (diff)
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<T, std::size_t> 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<std::pair<std::uint64_t, std::size>> --config-id; std::vector<std::pair<std::string, std::size>> --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; } }
Diffstat (limited to 'cli-tests/position/test.cli')
-rw-r--r--cli-tests/position/test.cli13
1 files changed, 13 insertions, 0 deletions
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 <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+include <vector>;
+include <utility>;
+include <cstddef>;
+
+class options
+{
+ std::pair<int, std::size_t> -a;
+ std::vector<std::pair<int, std::size_t> > -b;
+};