summaryrefslogtreecommitdiff
path: root/examples/hello/driver.cxx
blob: 30fdf6ea82b2917f00551fd8e99957caac3d2f4e (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      : examples/hello/driver.cxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// license   : MIT; see accompanying LICENSE file

#include <iostream>

#include "hello.hxx"

using namespace std;

void
usage (ostream& os)
{
  os << "usage: driver [options] <names>" << endl
     << "options:" << endl;
  options::print_usage (os);
}

int
main (int argc, char* argv[])
{
  try
  {
    int end; // End of options.
    options o (argc, argv, end);

    if (o.help ())
    {
      usage (cout);
      return 0;
    }

    if (end == argc)
    {
      cerr << "no names provided" << endl;
      usage (cerr);
      return 1;
    }

    // Print the greetings.
    //
    for (int i = end; i < argc; i++)
    {
      cout << o.greeting () << ", " << argv[i];

      for (unsigned int j = 0; j < o.exclamations (); j++)
        cout << '!';

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