summaryrefslogtreecommitdiff
path: root/cli-examples/file
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/file
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/file')
-rw-r--r--cli-examples/file/.gitignore1
-rw-r--r--cli-examples/file/README38
-rw-r--r--cli-examples/file/buildfile11
-rw-r--r--cli-examples/file/driver.cxx35
-rw-r--r--cli-examples/file/options.cli7
-rw-r--r--cli-examples/file/test.ops7
6 files changed, 99 insertions, 0 deletions
diff --git a/cli-examples/file/.gitignore b/cli-examples/file/.gitignore
new file mode 100644
index 0000000..c6e608b
--- /dev/null
+++ b/cli-examples/file/.gitignore
@@ -0,0 +1 @@
+options.?xx
diff --git a/cli-examples/file/README b/cli-examples/file/README
new file mode 100644
index 0000000..289fc64
--- /dev/null
+++ b/cli-examples/file/README
@@ -0,0 +1,38 @@
+This example shows how to allow the users of your application to supply
+options in files in addition to the command line.
+
+The example consists of the following files:
+
+options.cli
+ Command line interface description in the CLI language.
+
+options.hxx
+options.ixx
+options.cxx
+ Command line interface implementation in C++. These files are generated
+ by the CLI compiler from options.cli using the following command line:
+
+ cli --generate-file-scanner hello.cli
+
+ We use the --generate-file-scanner CLI compiler option to include the
+ argv_file_scanner scanner implementation which provides support for
+ reading options from files in addition to the command line.
+
+driver.cxx
+ Driver for the example. It first creates the argv_file_scanner object
+ and indicates that the values for the --options-file option should be
+ recognized as files containing additional options. It then passes this
+ scanner object to the option class which parses the command line. The
+ driver then prints the option values.
+
+test.ops
+ Sample options file.
+
+To run this example you can try the following command line:
+
+$ ./driver --verbose 2 --val 1 --options-file test.ops --val 4
+
+The output will be:
+
+verbosity: 5
+values: 1 2 3 4
diff --git a/cli-examples/file/buildfile b/cli-examples/file/buildfile
new file mode 100644
index 0000000..89675d8
--- /dev/null
+++ b/cli-examples/file/buildfile
@@ -0,0 +1,11 @@
+# file : file/buildfile
+# license : MIT; see accompanying LICENSE file
+
+exe{driver}: {hxx cxx}{* -options} cli.cxx{options} doc{README}
+exe{driver}: test.arguments = --options-file
+exe{driver}: file{test.ops}: test.input = true # Added after test.arguments.
+
+cxx.poptions =+ "-I$out_base"
+
+cli.cxx{options}: cli{options}
+cli.options = --generate-file-scanner
diff --git a/cli-examples/file/driver.cxx b/cli-examples/file/driver.cxx
new file mode 100644
index 0000000..b53574c
--- /dev/null
+++ b/cli-examples/file/driver.cxx
@@ -0,0 +1,35 @@
+// file : file/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#include <iostream>
+#include <iterator>
+#include <algorithm>
+
+#include "options.hxx"
+
+using namespace std;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ cli::argv_file_scanner s (argc, argv, "--options-file");
+ options o (s);
+
+ cout << "verbosity: " << o.verbose () << endl
+ << "values: ";
+
+ copy (o.val ().begin (),
+ o.val ().end (),
+ ostream_iterator<int> (cout, " "));
+
+ cerr << endl;
+ }
+ catch (const cli::exception& e)
+ {
+ cerr << e << endl;
+ return 1;
+ }
+}
diff --git a/cli-examples/file/options.cli b/cli-examples/file/options.cli
new file mode 100644
index 0000000..3e6db5a
--- /dev/null
+++ b/cli-examples/file/options.cli
@@ -0,0 +1,7 @@
+include <vector>;
+
+class options
+{
+ int --verbose;
+ std::vector<int> --val;
+};
diff --git a/cli-examples/file/test.ops b/cli-examples/file/test.ops
new file mode 100644
index 0000000..65fcf07
--- /dev/null
+++ b/cli-examples/file/test.ops
@@ -0,0 +1,7 @@
+# Sample options file. Empty lines and lines starting with '#' are
+# ignored.
+#
+--verbose 5
+
+--val 2
+--val=3