example_command_line.hh

Go to the documentation of this file.
00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 #ifndef PALUDIS_GUARD_DOC_EXAMPLES_EXAMPLE_COMMAND_LINE_HH
00004 #define PALUDIS_GUARD_DOC_EXAMPLES_EXAMPLE_COMMAND_LINE_HH 1
00005 
00006 #include <paludis/args/args.hh>
00007 #include <paludis/args/log_level_arg.hh>
00008 #include <paludis/paludis.hh>
00009 
00010 /** \file
00011  *
00012  * Basic command line handling for most examples.
00013  */
00014 
00015 namespace examples
00016 {
00017     /**
00018      * This class provides basic command line handling for most examples.
00019      *
00020      * Most Paludis clients should support at least '--help', '--version'
00021      * and '--log-level'. If paludis::EnvironmentFactory is used to create
00022      * the environment (as opposed to, say, paludis::NoConfigEnvironment),
00023      * then '--environment' must also be an option.
00024      *
00025      * Clients are free to use whichever command line handling library they
00026      * prefer, but for convenience all Paludis core clients use a common utility
00027      * library with a much simpler interface than that provided by overly C-ish
00028      * getopt derivatives.
00029      *
00030      * The command line is a singleton -- that is, only one instance of
00031      * it exists globally. This avoids the need to pass around lots of
00032      * parameters.
00033      */
00034     class CommandLine :
00035         public paludis::args::ArgsHandler,
00036         public paludis::InstantiationPolicy<CommandLine, paludis::instantiation_method::SingletonTag>
00037     {
00038         friend class paludis::InstantiationPolicy<CommandLine, paludis::instantiation_method::SingletonTag>;
00039 
00040         private:
00041             CommandLine();
00042             ~CommandLine();
00043 
00044         public:
00045             virtual void run(const int, const char * const * const,
00046                     const std::string & client, const std::string & env_var,
00047                     const std::string & env_prefix);
00048 
00049             ///\name Program information
00050             ///\{
00051 
00052             virtual std::string app_name() const;
00053             virtual std::string app_synopsis() const;
00054             virtual std::string app_description() const;
00055 
00056             ///\}
00057 
00058             ///\name Action arguments
00059             ///\{
00060 
00061             paludis::args::ArgsGroup action_args;
00062             paludis::args::SwitchArg a_version;
00063             paludis::args::SwitchArg a_help;
00064 
00065             ///\}
00066 
00067             ///\name General arguments
00068             ///{
00069 
00070             paludis::args::ArgsGroup general_args;
00071             paludis::args::LogLevelArg a_log_level;
00072             paludis::args::StringArg a_environment;
00073 
00074             ///}
00075     };
00076 
00077     /**
00078      * Show a '--help' message, and exit.
00079      */
00080     void show_help_and_exit(const char * const argv[]) PALUDIS_ATTRIBUTE((noreturn));
00081 
00082     /**
00083      * Show a '--version' message, and exit.
00084      */
00085     void show_version_and_exit() PALUDIS_ATTRIBUTE((noreturn));
00086 }
00087 
00088 #endif

Generated on Mon Sep 21 10:36:07 2009 for paludis by  doxygen 1.5.4