ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
cli.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_cli of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_CLI_CLI
9#define HPP_ALIB_CLI_CLI 1
10
11#if !defined (HPP_ALIB_CAMP_MESSAGE_EXCEPTION)
13#endif
14
15#if !defined (HPP_ALOX)
16# include "alib/alox.hpp"
17#endif
18
19#if !defined(HPP_ALIB_LANG_CAMP)
21#endif
22
23namespace alib { namespace cli {
24
25class CommandLine;
26
27/** ************************************************************************************************
28 * The module class for module \alib_cli_nl.
29 *
30 * This is a strict singleton class. The only instance is found with namespace variable
31 * \ref alib::CLI.
32 **************************************************************************************************/
33class Cli : public lang::Camp
34{
35 public:
36 /** ****************************************************************************************
37 * Constructor.<br>
38 * While this is public, it must not be invoked as this is a strict singleton type.
39 * (See notes in \ref alib_manual_camp_modules_campmodule).
40 ******************************************************************************************/
41 Cli();
42
43 protected:
44 /** ****************************************************************************************
45 * Initializes module module \alib_cli_nl.
46 *
47 * @param phase The initialization phase to perform.
48 ******************************************************************************************/
49 virtual void bootstrap( BootstrapPhases phase ) override;
50
51 /** ****************************************************************************************
52 * Terminates this module. (Nothing to do.)
53 * @param phase The shutdown phase to perform.
54 ******************************************************************************************/
55 virtual void shutdown( ShutdownPhases phase ) override
56 { (void) phase; }
57
58}; // class Cli
59
60/** ************************************************************************************************
61 * Exceptions of module #alib::cli.
62 * As usual with class \alib{lang;Exception}, some of the exceptions are "inner exceptions" that
63 * are caught internally and re-thrown with more information and a different exception code.
64 *
65 * The in this respect "external" exceptions that have to be caught by users of the library, are:
66 *
67 * - \b %NoCommandGiven,
68 * - \b %UnknownCommand,
69 * - \b %ParsingOptions and
70 * - \b %ParsingCommand.
71 **************************************************************************************************/
72enum class Exceptions
73{
74 // main exceptions to be handled by the user
75 NoCommandGiven = 1, ///< Unknown command given.
76 UnknownCommand = 2, ///< Unknown command given.
77 ParsingOptions =10, ///< General option parse error. Adds option help text.
78 ParsingCommand =20, ///< General parameter parse error. Adds command help text.
79
80 // inner exceptions
81 MissingOptionValue =11, ///< Missing argument when reading option.
82 ///< (Will be generalized with ParsingOptions.)
83 IllegalOptionNameContinuation =12, ///< An option was given in long name, but continued after
84 ///< its name in an undefined way.
85 ///< (Will be generalized with ParsingOptions.)
86
87 MissingParameterValue =21, ///< Missing argument when reading parameter.
88 ///< (Will be generalized with ParameterError.)
89
90 END_OF_ENUM
91};
92
93/** ************************************************************************************************
94 * Dry run modes.
95 **************************************************************************************************/
96enum class DryRunModes
97{
98 Off , ///< No dry run
99 CLIArgs , ///< Displays the results of the command line argument parsing.
100 CLIDeclarations, ///< Just displays the cli setup. This is more for debugging or interested users.
101 Application , ///< Dry run on application level: Given commands are invoked, nothing is
102 ///< executed, but probably log information is written. Application specific behavior.
103 ///< This is the default if no argument is given to the dry-run opton
104};
105
106
107} // namespace alib[::cli]
108
109/** The singleton instance of \alibcamp class \alib{cli;Cli}. */
110extern ALIB_API cli::Cli CLI;
111
112} // namespace [alib]
113
118
119#endif // HPP_ALIB_CLI_CLI
virtual void bootstrap(BootstrapPhases phase) override
Definition cli.cpp:49
virtual void shutdown(ShutdownPhases phase) override
Definition cli.hpp:55
#define ALIB_ENUMS_ASSIGN_RECORD(TEnum, TRecord)
Definition records.hpp:752
#define ALIB_API
Definition alib.hpp:538
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
Definition vtable.inl:477
#define ALIB_RESOURCED_IN_MODULE(T, Camp, ResName)
DryRunModes
Definition cli.hpp:97
@ CLIDeclarations
Just displays the cli setup. This is more for debugging or interested users.
@ CLIArgs
Displays the results of the command line argument parsing.
Exceptions
Definition cli.hpp:73
@ ParsingOptions
General option parse error. Adds option help text.
@ ParsingCommand
General parameter parse error. Adds command help text.
@ NoCommandGiven
Unknown command given.
@ UnknownCommand
Unknown command given.
Definition alib.cpp:57
ShutdownPhases
Definition camp.hpp:35
cli::Cli CLI
Definition cli.cpp:30
cli::CommandLine CommandLine
Type alias in namespace alib.
BootstrapPhases
Definition camp.hpp:26