paludis  Version 2.6.0
example_command_line.hh
Go to the documentation of this file.
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 #ifndef PALUDIS_GUARD_DOC_EXAMPLES_EXAMPLE_COMMAND_LINE_HH
4 #define PALUDIS_GUARD_DOC_EXAMPLES_EXAMPLE_COMMAND_LINE_HH 1
5 
6 #include <paludis/args/args.hh>
8 #include <paludis/paludis.hh>
9 
10 /** \file
11  *
12  * Basic command line handling for most examples.
13  */
14 
15 namespace examples
16 {
17  /**
18  * This class provides basic command line handling for most examples.
19  *
20  * Most Paludis clients should support at least '--help', '--version'
21  * and '--log-level'. If paludis::EnvironmentFactory is used to create
22  * the environment then '--environment' must also be an option.
23  *
24  * Clients are free to use whichever command line handling library they
25  * prefer, but for convenience all Paludis core clients use a common utility
26  * library with a much simpler interface than that provided by overly C-ish
27  * getopt derivatives.
28  *
29  * The command line is a singleton -- that is, only one instance of
30  * it exists globally. This avoids the need to pass around lots of
31  * parameters.
32  */
33  class CommandLine :
35  public paludis::Singleton<CommandLine>
36  {
37  friend class paludis::Singleton<CommandLine>;
38 
39  private:
40  CommandLine();
41  ~CommandLine();
42 
43  public:
44  virtual void run(const int, const char * const * const,
45  const std::string & client, const std::string & env_var,
46  const std::string & env_prefix);
47 
48  ///\name Program information
49  ///\{
50 
51  virtual std::string app_name() const;
52  virtual std::string app_synopsis() const;
53  virtual std::string app_description() const;
54 
55  ///\}
56 
57  ///\name Action arguments
58  ///\{
59 
60  paludis::args::ArgsGroup action_args;
61  paludis::args::SwitchArg a_version;
63 
64  ///\}
65 
66  ///\name General arguments
67  ///{
68 
69  paludis::args::ArgsGroup general_args;
70  paludis::args::LogLevelArg a_log_level;
71  paludis::args::StringArg a_environment;
72 
73  ///}
74  };
75 
76  /**
77  * Show a '--help' message, and exit.
78  */
79  void show_help_and_exit(const char * const argv[]) PALUDIS_ATTRIBUTE((noreturn));
80 
81  /**
82  * Show a '--version' message, and exit.
83  */
84  void show_version_and_exit() PALUDIS_ATTRIBUTE((noreturn));
85 }
86 
87 #endif
Definition: args_group.hh:50
virtual std::string app_synopsis() const
Definition: example_command_line.cc:42
Definition: example_command_line.hh:15
virtual std::string app_name() const
Definition: example_command_line.cc:36
Definition: log_level_arg.hh:47
Definition: args_option.hh:204
virtual std::string app_description() const
Definition: example_command_line.cc:48
Definition: args_option.hh:233
void show_version_and_exit() PALUDIS_ATTRIBUTE((noreturn))
Definition: example_command_line.cc:68
Definition: singleton.hh:44
Definition: args_handler.hh:59
void show_help_and_exit(const char *const argv[]) PALUDIS_ATTRIBUTE((noreturn))
Definition: example_command_line.cc:58
Definition: example_command_line.hh:33
#define PALUDIS_ATTRIBUTE(x)
Definition: attributes.hh:53