blob: ac9c580a9a0d22f97c69d11dbd1cb3f79a28f65c (
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
#ifndef PALUDIS_GUARD_DOC_EXAMPLES_EXAMPLE_COMMAND_LINE_HH
#define PALUDIS_GUARD_DOC_EXAMPLES_EXAMPLE_COMMAND_LINE_HH 1
#include <paludis/args/args.hh>
#include <paludis/args/log_level_arg.hh>
#include <paludis/paludis.hh>
/** \file
*
* Basic command line handling for most examples.
*/
namespace examples
{
/**
* This class provides basic command line handling for most examples.
*
* Most Paludis clients should support at least '--help', '--version'
* and '--log-level'. If paludis::EnvironmentFactory is used to create
* the environment then '--environment' must also be an option.
*
* Clients are free to use whichever command line handling library they
* prefer, but for convenience all Paludis core clients use a common utility
* library with a much simpler interface than that provided by overly C-ish
* getopt derivatives.
*
* The command line is a singleton -- that is, only one instance of
* it exists globally. This avoids the need to pass around lots of
* parameters.
*/
class CommandLine :
public paludis::args::ArgsHandler,
public paludis::Singleton<CommandLine>
{
friend class paludis::Singleton<CommandLine>;
private:
CommandLine();
~CommandLine();
public:
virtual void run(const int, const char * const * const,
const std::string & client, const std::string & env_var,
const std::string & env_prefix);
///\name Program information
///\{
virtual std::string app_name() const;
virtual std::string app_synopsis() const;
virtual std::string app_description() const;
///\}
///\name Action arguments
///\{
paludis::args::ArgsGroup action_args;
paludis::args::SwitchArg a_version;
paludis::args::SwitchArg a_help;
///\}
///\name General arguments
///{
paludis::args::ArgsGroup general_args;
paludis::args::LogLevelArg a_log_level;
paludis::args::StringArg a_environment;
///}
};
/**
* Show a '--help' message, and exit.
*/
void show_help_and_exit(const char * const argv[]) PALUDIS_ATTRIBUTE((noreturn));
/**
* Show a '--version' message, and exit.
*/
void show_version_and_exit() PALUDIS_ATTRIBUTE((noreturn));
}
#endif
|