From 720c5a33b6a49cf328fdd7611f49153cf8f60247 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 8 Apr 2020 14:51:57 +0300 Subject: Separate tests and examples into individual packages Also make cli module to be explicitly enabled via the config.cli configuration variable. --- examples/.gitignore | 1 - examples/README | 15 ----------- examples/build/.gitignore | 3 --- examples/build/bootstrap.build | 8 ------ examples/build/root.build | 36 ------------------------- examples/buildfile | 4 --- examples/features/.gitignore | 1 - examples/features/README | 20 -------------- examples/features/buildfile | 8 ------ examples/features/driver.cxx | 61 ------------------------------------------ examples/features/options.cli | 39 --------------------------- examples/file/.gitignore | 1 - examples/file/README | 38 -------------------------- examples/file/buildfile | 11 -------- examples/file/driver.cxx | 35 ------------------------ examples/file/options.cli | 7 ----- examples/file/test.ops | 7 ----- examples/hello/.gitignore | 1 - examples/hello/README | 26 ------------------ examples/hello/buildfile | 9 ------- examples/hello/driver.cxx | 58 --------------------------------------- examples/hello/hello.cli | 18 ------------- 22 files changed, 407 deletions(-) delete mode 100644 examples/.gitignore delete mode 100644 examples/README delete mode 100644 examples/build/.gitignore delete mode 100644 examples/build/bootstrap.build delete mode 100644 examples/build/root.build delete mode 100644 examples/buildfile delete mode 100644 examples/features/.gitignore delete mode 100644 examples/features/README delete mode 100644 examples/features/buildfile delete mode 100644 examples/features/driver.cxx delete mode 100644 examples/features/options.cli delete mode 100644 examples/file/.gitignore delete mode 100644 examples/file/README delete mode 100644 examples/file/buildfile delete mode 100644 examples/file/driver.cxx delete mode 100644 examples/file/options.cli delete mode 100644 examples/file/test.ops delete mode 100644 examples/hello/.gitignore delete mode 100644 examples/hello/README delete mode 100644 examples/hello/buildfile delete mode 100644 examples/hello/driver.cxx delete mode 100644 examples/hello/hello.cli (limited to 'examples') 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 -// license : MIT; see accompanying LICENSE file - -#include -#include -#include - -#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 (cerr, " ")); - cerr << endl; - } - - if (!o.set ().empty ()) - { - copy (o.set ().begin (), o.set ().end (), - ostream_iterator (cerr, " ")); - cerr << endl; - } - - // --map | -m - // - typedef map 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 ; -include ; -include ; -include ; - -// 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 --vector | -v; - std::set --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 --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 -// license : MIT; see accompanying LICENSE file - -#include -#include -#include - -#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 (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 ; - -class options -{ - int --verbose; - std::vector --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 -// license : MIT; see accompanying LICENSE file - -#include - -#include "hello.hxx" - -using namespace std; - -void -usage (ostream& os) -{ - os << "usage: driver [options] " << 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 ; - -class options -{ - bool --help {"Print usage information and exit."}; - - std::string --greeting = "Hello" - { - "", - "Use as a greeting phrase instead of the default \"Hello\"." - }; - - unsigned int --exclamations = 1 - { - "", - "Print exclamation marks instead of 1 by default." - }; -}; -- cgit v1.1