diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-08-03 14:11:17 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-08-03 14:11:17 +0200 |
commit | 0426335af0e7577148903be7a2534c4ced06cd3b (patch) | |
tree | 9d7d1de01c9e438097cfd9d235f4df3206761b54 /cli-tests/position/buildfile | |
parent | a54c695583015812280228bcadca3057397d4dd0 (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/buildfile')
-rw-r--r-- | cli-tests/position/buildfile | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/cli-tests/position/buildfile b/cli-tests/position/buildfile new file mode 100644 index 0000000..371cc54 --- /dev/null +++ b/cli-tests/position/buildfile @@ -0,0 +1,9 @@ +# file : position/buildfile +# license : MIT; see accompanying LICENSE file + +exe{driver}: {hxx cxx}{* -test} cli.cxx{test} testscript + +cxx.poptions =+ "-I$out_base" + +cli.cxx{test}: cli{test} +cli.options = --generate-file-scanner --generate-specifier |