summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/.gitignore1
-rw-r--r--examples/README15
-rw-r--r--examples/build/.gitignore3
-rw-r--r--examples/build/bootstrap.build8
-rw-r--r--examples/build/root.build36
-rw-r--r--examples/buildfile4
-rw-r--r--examples/features/.gitignore1
-rw-r--r--examples/features/README20
-rw-r--r--examples/features/buildfile8
-rw-r--r--examples/features/driver.cxx61
-rw-r--r--examples/features/options.cli39
-rw-r--r--examples/file/.gitignore1
-rw-r--r--examples/file/README38
-rw-r--r--examples/file/buildfile11
-rw-r--r--examples/file/driver.cxx35
-rw-r--r--examples/file/options.cli7
-rw-r--r--examples/file/test.ops7
-rw-r--r--examples/hello/.gitignore1
-rw-r--r--examples/hello/README26
-rw-r--r--examples/hello/buildfile9
-rw-r--r--examples/hello/driver.cxx58
-rw-r--r--examples/hello/hello.cli18
22 files changed, 0 insertions, 407 deletions
diff --git a/examples/.gitignore b/examples/.gitignore
deleted file mode 100644
index e54525b..0000000
--- a/examples/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-driver
diff --git a/examples/README b/examples/README
deleted file mode 100644
index 84ef156..0000000
--- a/examples/README
+++ /dev/null
@@ -1,15 +0,0 @@
-This directory contains a number of examples that show how to use the CLI
-language and compiler to implement command line interface parsing in C++.
-The following list gives an overview of each example. See the README files
-in example directories for more information on each example.
-
-hello
- A simple "Hello, world!" example that shows how to implement a very basic
- command line interface using CLI.
-
-features
- Shows how to use various features of the CLI language.
-
-file
- Shows how to allow the users of your application to supply options in
- files in addition to the command line.
diff --git a/examples/build/.gitignore b/examples/build/.gitignore
deleted file mode 100644
index 4a730a3..0000000
--- a/examples/build/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-config.build
-root/
-bootstrap/
diff --git a/examples/build/bootstrap.build b/examples/build/bootstrap.build
deleted file mode 100644
index 78d91f7..0000000
--- a/examples/build/bootstrap.build
+++ /dev/null
@@ -1,8 +0,0 @@
-# file : examples/build/bootstrap.build
-# license : MIT; see accompanying LICENSE file
-
-project = # Unnamed subproject.
-
-using config
-using dist
-using test
diff --git a/examples/build/root.build b/examples/build/root.build
deleted file mode 100644
index 5f08770..0000000
--- a/examples/build/root.build
+++ /dev/null
@@ -1,36 +0,0 @@
-# file : examples/build/root.build
-# license : MIT; see accompanying LICENSE file
-
-cxx.std = latest
-
-using cxx
-
-hxx{*}: extension = hxx
-ixx{*}: extension = ixx
-txx{*}: extension = txx
-cxx{*}: extension = cxx
-
-if ($cxx.target.system == 'win32-msvc')
- cxx.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
-
-if ($cxx.class == 'msvc')
- cxx.coptions += /wd4251 /wd4275 /wd4800
-
-# Load cli module. It must be available from the system or from the base
-# project. Generating files with cli is a part of the examples, so distributing
-# pre-generated files would be meaningless.
-#
-# @@ How to initialize the module to use a base project cli executable by
-# default (if present and not configured to use another one)? Should it be
-# assignment like 'config.cli = $out_root/../cli/cli' prior 'using config'
-# in bootstrap.build, but what if it doesn't exist?
-#
-using cli
-
-# Every exe{} in this subproject is by default a test.
-#
-exe{*}: test = true
-
-# Specify the test target for cross-testing.
-#
-test.target = $cxx.target
diff --git a/examples/buildfile b/examples/buildfile
deleted file mode 100644
index 34801a9..0000000
--- a/examples/buildfile
+++ /dev/null
@@ -1,4 +0,0 @@
-# file : examples/buildfile
-# license : MIT; see accompanying LICENSE file
-
-./: {*/ -build/} README
diff --git a/examples/features/.gitignore b/examples/features/.gitignore
deleted file mode 100644
index c6e608b..0000000
--- a/examples/features/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-options.?xx
diff --git a/examples/features/README b/examples/features/README
deleted file mode 100644
index 9416320..0000000
--- a/examples/features/README
+++ /dev/null
@@ -1,20 +0,0 @@
-This example shows how to use various features of the CLI language.
-
-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 hello.cli using the following command line:
-
- cli options.cli
-
-driver.cxx
- Driver for the example. It first instantiates the option class which parses
- the command line. The driver then examines and prints the option values.
-
-To run the example you can try various command lines suggested in options.cli.
diff --git a/examples/features/buildfile b/examples/features/buildfile
deleted file mode 100644
index 29ce2c7..0000000
--- a/examples/features/buildfile
+++ /dev/null
@@ -1,8 +0,0 @@
-# file : examples/features/buildfile
-# license : MIT; see accompanying LICENSE file
-
-exe{driver}: {hxx cxx}{* -options} cli.cxx{options} doc{README}
-
-cxx.poptions =+ "-I$out_base"
-
-cli.cxx{options}: cli{options}
diff --git a/examples/features/driver.cxx b/examples/features/driver.cxx
deleted file mode 100644
index 33ba362..0000000
--- a/examples/features/driver.cxx
+++ /dev/null
@@ -1,61 +0,0 @@
-// file : examples/features/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
- {
- features::options o (argc, argv);
-
- // --out-dir | -o
- //
- if (!o.out_dir ().empty ())
- cerr << "output dir: " << o.out_dir () << endl;
-
- // --first-name & --last-name
- //
- cerr << "first name: " << o.first_name () << endl
- << "last name : " << o.last_name () << endl;
-
- // --vector | -v & --set | -s
- //
- if (!o.vector ().empty ())
- {
- copy (o.vector ().begin (), o.vector ().end (),
- ostream_iterator<int> (cerr, " "));
- cerr << endl;
- }
-
- if (!o.set ().empty ())
- {
- copy (o.set ().begin (), o.set ().end (),
- ostream_iterator<int> (cerr, " "));
- cerr << endl;
- }
-
- // --map | -m
- //
- typedef map<std::string, std::string> str_map;
- const str_map& m = o.map ();
- str_map::const_iterator i (m.find ("a"));
-
- if (i != m.end ())
- cerr << "value for the 'a' key: " << i->second << endl;
-
- }
- catch (const cli::exception& e)
- {
- cerr << e << endl;
- return 1;
- }
-}
diff --git a/examples/features/options.cli b/examples/features/options.cli
deleted file mode 100644
index ea055b3..0000000
--- a/examples/features/options.cli
+++ /dev/null
@@ -1,39 +0,0 @@
-include <set>;
-include <map>;
-include <vector>;
-include <string>;
-
-// We can place the options classes into namespaces which mapped to C++
-// namespaces.
-//
-namespace features
-{
- class options
- {
- // We can have several aliases for the same option. The first one is used
- // to derive the accessor name.
- //
- std::string --out-dir | -o;
-
- // We can use both assignment and constructor notations to provide the
- // default option value.
- //
- std::string --first-name = "John";
- std::string --last-name ("Mr John Doe", 8, 3);
-
- // We can use containers to to collect option value. If we have a command
- // line like this: -v 1 -v 2 -v 1 -s 1 -s 2 -s 1 then the vector returned
- // by the vector() accessor will contain three elements: 1, 2, and 1 while
- // the set returned by the set() accessor will contain two elements: 1 and
- // 2.
- //
- std::vector<int> --vector | -v;
- std::set<int> --set | -s;
-
- // We can also use maps. In this case the option value is expected to have
- // two parts: the key and the value, separated by '='. For example: -m a=A
- // -m =B -m c= -m d (same as -m d=).
- //
- std::map<std::string, std::string> --map | -m;
- };
-}
diff --git a/examples/file/.gitignore b/examples/file/.gitignore
deleted file mode 100644
index c6e608b..0000000
--- a/examples/file/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-options.?xx
diff --git a/examples/file/README b/examples/file/README
deleted file mode 100644
index 289fc64..0000000
--- a/examples/file/README
+++ /dev/null
@@ -1,38 +0,0 @@
-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/examples/file/buildfile b/examples/file/buildfile
deleted file mode 100644
index eadfc66..0000000
--- a/examples/file/buildfile
+++ /dev/null
@@ -1,11 +0,0 @@
-# file : examples/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/examples/file/driver.cxx b/examples/file/driver.cxx
deleted file mode 100644
index d187559..0000000
--- a/examples/file/driver.cxx
+++ /dev/null
@@ -1,35 +0,0 @@
-// file : examples/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/examples/file/options.cli b/examples/file/options.cli
deleted file mode 100644
index 3e6db5a..0000000
--- a/examples/file/options.cli
+++ /dev/null
@@ -1,7 +0,0 @@
-include <vector>;
-
-class options
-{
- int --verbose;
- std::vector<int> --val;
-};
diff --git a/examples/file/test.ops b/examples/file/test.ops
deleted file mode 100644
index 65fcf07..0000000
--- a/examples/file/test.ops
+++ /dev/null
@@ -1,7 +0,0 @@
-# Sample options file. Empty lines and lines starting with '#' are
-# ignored.
-#
---verbose 5
-
---val 2
---val=3
diff --git a/examples/hello/.gitignore b/examples/hello/.gitignore
deleted file mode 100644
index d73130a..0000000
--- a/examples/hello/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-hello.?xx
diff --git a/examples/hello/README b/examples/hello/README
deleted file mode 100644
index dd14b01..0000000
--- a/examples/hello/README
+++ /dev/null
@@ -1,26 +0,0 @@
-This is a "Hello, world!" example that shows how to implement a very basic
-command line interface using CLI.
-
-The example consists of the following files:
-
-hello.cli
- Command line interface description in the CLI language.
-
-hello.hxx
-hello.ixx
-hello.cxx
- Command line interface implementation in C++. These files are generated
- by the CLI compiler from hello.cli using the following command line:
-
- cli hello.cli
-
-driver.cxx
- Driver for the example. It first instantiates the option class which parses
- the command line. The driver then examines the options and prints the
- greeting string for each name passed as an argument.
-
-To run the example you can try the following command lines:
-
-$ ./driver --help
-$ ./driver John Jane
-$ ./driver --greeting Hi --exclamations 3 John Jane
diff --git a/examples/hello/buildfile b/examples/hello/buildfile
deleted file mode 100644
index 9a11b29..0000000
--- a/examples/hello/buildfile
+++ /dev/null
@@ -1,9 +0,0 @@
-# file : examples/hello/buildfile
-# license : MIT; see accompanying LICENSE file
-
-exe{driver}: {hxx cxx}{* -hello} cli.cxx{hello} doc{README}
-exe{driver}: test.arguments = --greeting Hi John Jane
-
-cxx.poptions =+ "-I$out_base"
-
-cli.cxx{hello}: cli{hello}
diff --git a/examples/hello/driver.cxx b/examples/hello/driver.cxx
deleted file mode 100644
index 30fdf6e..0000000
--- a/examples/hello/driver.cxx
+++ /dev/null
@@ -1,58 +0,0 @@
-// 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;
- }
-}
diff --git a/examples/hello/hello.cli b/examples/hello/hello.cli
deleted file mode 100644
index b75e1b8..0000000
--- a/examples/hello/hello.cli
+++ /dev/null
@@ -1,18 +0,0 @@
-include <string>;
-
-class options
-{
- bool --help {"Print usage information and exit."};
-
- std::string --greeting = "Hello"
- {
- "<text>",
- "Use <text> as a greeting phrase instead of the default \"Hello\"."
- };
-
- unsigned int --exclamations = 1
- {
- "<num>",
- "Print <num> exclamation marks instead of 1 by default."
- };
-};