diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-09-27 19:27:00 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-09-27 19:27:00 +0200 |
commit | b24bb543e97bc7ad440e66c5a1aa3cd0e62e5a69 (patch) | |
tree | 43a206f282b311d3bbaf71ad68319fdbba8ab1bb /examples/hello | |
parent | cede34ad1ac6730f5f2c88b4dd655f90589ae803 (diff) |
Print proper usage, complain if no names provided
Diffstat (limited to 'examples/hello')
-rw-r--r-- | examples/hello/driver.cxx | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/examples/hello/driver.cxx b/examples/hello/driver.cxx index c211601..6641d4b 100644 --- a/examples/hello/driver.cxx +++ b/examples/hello/driver.cxx @@ -9,6 +9,15 @@ using namespace std; +void +usage () +{ + cerr << "usage: driver <options> <names>" << endl + << " [--help]" << endl + << " [--greeting|-g <string>]" << endl + << " [--exclamations|-e <integer>]" << endl; +} + int main (int argc, char* argv[]) { @@ -19,10 +28,17 @@ main (int argc, char* argv[]) if (o.help ()) { - cerr << "hello v. 1.0.0" << endl; + usage (); return 0; } + if (end == argc) + { + cerr << "no names provided" << endl; + usage (); + return 1; + } + for (int i = end; i < argc; i++) { cout << o.greeting () << ", " << argv[i]; @@ -36,6 +52,7 @@ main (int argc, char* argv[]) catch (const cli::exception& e) { cerr << e << endl; + usage (); return 1; } } |