summaryrefslogtreecommitdiff
path: root/cli-examples/hello/driver.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-04-08 14:51:57 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-04-27 11:38:53 +0300
commit720c5a33b6a49cf328fdd7611f49153cf8f60247 (patch)
tree9725f3d1f42ec90fde84520f49647edea013ce5e /cli-examples/hello/driver.cxx
parent3183f3bb927a90783ae0aeaf190a0919377aabe4 (diff)
Separate tests and examples into individual packages
Also make cli module to be explicitly enabled via the config.cli configuration variable.
Diffstat (limited to 'cli-examples/hello/driver.cxx')
-rw-r--r--cli-examples/hello/driver.cxx58
1 files changed, 58 insertions, 0 deletions
diff --git a/cli-examples/hello/driver.cxx b/cli-examples/hello/driver.cxx
new file mode 100644
index 0000000..bc37564
--- /dev/null
+++ b/cli-examples/hello/driver.cxx
@@ -0,0 +1,58 @@
+// file : 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;
+ }
+}