summaryrefslogtreecommitdiff
path: root/tests/group/driver.cxx
blob: f24cdd837c2284a21113588ba4b2dceae76d9f60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// file      : tests/group/driver.cxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// license   : MIT; see accompanying LICENSE file

// Test group_scanner.
//

#include <iostream>

#include "test.hxx"

using namespace std;

int
main (int argc, char* argv[])
{
  try
  {
    using namespace cli;

    // Mode flags.
    //
    // 'g' -- don't handle groups.
    // 's' -- skip arguments.
    //
    string m (argv[1]);

    argv_scanner as (--argc, ++argv);
    group_scanner s (as);

    while (s.more ())
    {
      if (m.find ('s') == string::npos)
      {
        const char* a (s.next ());
        cout << "'" << a << "'";
      }
      else
        s.skip ();

      if (m.find ('g') == string::npos)
      {
        scanner& gs (s.group ());
        while (gs.more ())
          cout << " '" << gs.next () << "'";
      }

      cout << endl;
    }

    return 0;
  }
  catch (const cli::exception& e)
  {
    cerr << e << endl;
    return 1;
  }
}