diff options
| author | Jörg Frings-Fürst <jff@merkur> | 2014-05-18 16:08:14 +0200 | 
|---|---|---|
| committer | Jörg Frings-Fürst <jff@merkur> | 2014-05-18 16:08:14 +0200 | 
| commit | a15cf65c44d5c224169c32ef5495b68c758134b7 (patch) | |
| tree | 3419f58fc8e1b315ba8171910ee044c5d467c162 /libcult/examples/cli | |
Imported Upstream version 3.3.0.2upstream/3.3.0.2
Diffstat (limited to 'libcult/examples/cli')
| -rw-r--r-- | libcult/examples/cli/cli.cxx | 65 | ||||
| -rw-r--r-- | libcult/examples/cli/makefile | 48 | 
2 files changed, 113 insertions, 0 deletions
diff --git a/libcult/examples/cli/cli.cxx b/libcult/examples/cli/cli.cxx new file mode 100644 index 0000000..922a23d --- /dev/null +++ b/libcult/examples/cli/cli.cxx @@ -0,0 +1,65 @@ +// file      : examples/cli/cli.cxx +// author    : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2005-2010 Boris Kolpackov +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <cult/types.hxx> + +#include <cult/cli/options.hxx> +#include <cult/cli/options-spec.hxx> +#include <cult/cli/options-parser.hxx> + +#include <iostream> + +using std::cerr; +using std::endl; + +using namespace Cult; + +namespace +{ +  extern Char const help[] = "help"; +  extern Char const version[] = "version"; +  extern Char const outdir[] = "outdir"; +} + +typedef +CLI::Options<help, Boolean, +             version, Boolean, +             outdir, String> +Options; + +Int +main (Int argc, Char* argv[]) +{ +  try +  { +    Options options (CLI::parse<Options> (argc, argv)); + +    if (options.value<help> ()) +    { +      cerr << "usage: " << argv[0] << " [--help] [--version] [--outdir <dir>]" +           << endl; +      return 0; +    } + +    if (options.value<version> ()) +    { +      cerr << argv[0] << " 1.2.3" << endl; +      return 0; +    } + +    if (String dir = options.value<outdir> ()) +    { +      cerr << "outdir: " << dir << endl; +    } +  } +  catch (CLI::UnexpectedOption const& e) +  { +    cerr << "unexpected option " << e.option () <<endl; +  } +  catch (CLI::OptionFormat const& e) +  { +    cerr << "bad format for " << e.option () << endl; +  } +} diff --git a/libcult/examples/cli/makefile b/libcult/examples/cli/makefile new file mode 100644 index 0000000..004f135 --- /dev/null +++ b/libcult/examples/cli/makefile @@ -0,0 +1,48 @@ +# file      : examples/cli/makefile +# author    : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2005-2010 Boris Kolpackov +# license   : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +cxx_tun   := cli.cxx +cxx_obj   := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od    := $(cxx_obj:.o=.o.d) + +cult.l             := $(out_root)/cult/cult.l +cult.l.cpp-options := $(out_root)/cult/cult.l.cpp-options + +cli     := $(out_base)/cli +clean   := $(out_base)/.clean + + +# Build. +# +$(cli): $(cxx_obj) $(cult.l) + +$(cxx_obj) $(cxx_od): $(cult.l.cpp-options) + +$(call include-dep,$(cxx_od)) + + +# Convenience alias for default target. +# +$(out_base)/: $(cli) + + +# Clean. +# +$(clean): $(cli).o.clean             \ +  $(addsuffix .cxx.clean,$(cxx_obj)) \ +  $(addsuffix .cxx.clean,$(cxx_od)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cult/makefile)  | 
