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