MySQL 8.0.40
Source Code Documentation
plugin_info_app.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2017, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQLROUTER_PLUGIN_INFO_APP_INCLUDED
27#define MYSQLROUTER_PLUGIN_INFO_APP_INCLUDED
28
29#include <ostream>
30
32
33// name displayed with --version request
34const std::string kPluginInfoAppName = "MySQL Router - Plugin Info App";
35
36/**
37 * exception thrown by the frontend.
38 *
39 * Should be presented to the user.
40 */
41class FrontendError : public std::runtime_error {
42 public:
43 FrontendError(const std::string &what) : std::runtime_error(what) {}
44};
45
46/**
47 * frontend error that involved the command-line options.
48 *
49 * should bet handled by showing the user the help-text or a high how to get the
50 * help
51 */
52class UsageError : public FrontendError {
53 public:
54 UsageError(const std::string &what) : FrontendError(what) {}
55};
56
57/** @class Plugin_info
58 *
59 * @brief Application class, enables testing of the application through the
60 * selecting input parameters and regular and error outputs.
61 *
62 **/
63class PluginInfoFrontend final {
64 public:
65 enum class Cmd { INFO, SHOW_HELP, SHOW_VERSION };
66 struct Config {
68 std::string filename;
69 std::string username;
70 };
71
72 /** Constructor.
73 *
74 * @brief Normal application operation exepcts 3 parameters:
75 * {exe_name} {path_to_plugin_file} {plugin_name}
76 * This retrieves the data read from the plugin file to the output
77 *stream.
78 *
79 * Other supported options are:
80 * {exe_name} --help outputs application usage to the error stream
81 * {exe_name} --version outputs application version to the error
82 *stream
83 *
84 * @param exe_name name of the started executable
85 * @param arguments command line arguments (without exe_name)
86 * @param out Output stream for the data printed by the application
87 *
88 **/
89 PluginInfoFrontend(const std::string &exe_name,
90 const std::vector<std::string> &arguments,
91 std::ostream &out);
92
93 std::string get_version() const noexcept;
94
95 // should be const, but arg_handler's
96 std::string get_help(const size_t screen_width = 80) const;
97
98 /**
99 * Executes the action requested from the application with the
100 * parameters passed to the constructor.
101 *
102 * Note: Redirects the output to the streams provided to the constructor.
103 *
104 * @returns exit-code
105 * @retval EXIT_SUCESS on success
106 * @retval EXIT_FAILURE if an error occurred.
107 */
108 int run();
109
110 private:
112
115 std::ostream &cout_;
116
117 Config config_; // must be last as config-handling may depend on cin, ...
118 // and arg_handler_
119};
120
121#endif
Defining the commandline argument handler class CmdArgHandler.
Handles command line arguments.
Definition: arg_handler.h:141
exception thrown by the frontend.
Definition: passwd.h:42
FrontendError(const std::string &what)
Definition: plugin_info_app.h:43
Definition: plugin_info_app.h:63
std::ostream & cout_
Definition: plugin_info_app.h:115
Cmd
Definition: plugin_info_app.h:65
std::string get_version() const noexcept
Definition: plugin_info_app.cc:52
PluginInfoFrontend(const std::string &exe_name, const std::vector< std::string > &arguments, std::ostream &out)
Constructor.
Definition: plugin_info_app.cc:38
CmdArgHandler arg_handler_
Definition: plugin_info_app.h:114
Config config_
Definition: plugin_info_app.h:117
int run()
Executes the action requested from the application with the parameters passed to the constructor.
Definition: plugin_info_app.cc:105
void prepare_command_options()
Definition: plugin_info_app.cc:93
std::string get_help(const size_t screen_width=80) const
Definition: plugin_info_app.cc:64
std::string program_name_
Definition: plugin_info_app.h:113
frontend error that involved the command-line options.
Definition: passwd.h:53
UsageError(const std::string &what)
Definition: plugin_info_app.h:54
Definition: gcs_xcom_synode.h:64
const std::string kPluginInfoAppName
Definition: plugin_info_app.h:34
Definition: plugin_info_app.h:66
std::string username
Definition: plugin_info_app.h:69
std::string filename
Definition: plugin_info_app.h:68
Cmd cmd
Definition: plugin_info_app.h:67