blob: 922a23d7cae2bd321538eb985ae5152c6f4a9373 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
}
}
|