summaryrefslogtreecommitdiff
path: root/examples/features
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 /examples/features
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 'examples/features')
-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
5 files changed, 0 insertions, 129 deletions
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;
- };
-}