mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
nodetool: prepare operation related classes for suboperations
Modify operation and add operation_action class so that information about suboperations is stored. It's a preparation for adding suboperations support to nodetool.
This commit is contained in:
@@ -363,6 +363,18 @@ keyspace_and_table parse_keyspace_and_table(scylla_rest_client& client, const bp
|
||||
}
|
||||
|
||||
using operation_func = void(*)(scylla_rest_client&, const bpo::variables_map&);
|
||||
struct operation_action{
|
||||
std::optional<operation_func> func = std::nullopt;
|
||||
std::map<sstring, operation_action> suboperation_funcs = {};
|
||||
|
||||
operation_action(operation_func f)
|
||||
: func(std::move(f))
|
||||
{}
|
||||
|
||||
operation_action(std::map<sstring, operation_action> subfs)
|
||||
: suboperation_funcs(std::move(subfs))
|
||||
{}
|
||||
};
|
||||
|
||||
std::map<operation, operation_func> get_operations_with_func();
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace bpo = boost::program_options;
|
||||
namespace tools::utils {
|
||||
|
||||
bool operation::matches(std::string_view name) const {
|
||||
return _name == name || std::ranges::find(_aliases, name) != _aliases.end();
|
||||
return _name[0] == name || std::ranges::find(_aliases, name) != _aliases.end();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -83,13 +83,13 @@ public:
|
||||
};
|
||||
|
||||
class operation {
|
||||
std::string _name;
|
||||
std::vector<std::string> _name = {};
|
||||
std::vector<std::string> _aliases;
|
||||
std::string _summary;
|
||||
std::string _description;
|
||||
std::vector<operation_option> _options;
|
||||
std::vector<operation_option> _positional_options;
|
||||
|
||||
std::vector<operation> _suboperations;
|
||||
public:
|
||||
operation(
|
||||
std::string name,
|
||||
@@ -97,13 +97,18 @@ public:
|
||||
std::string summary,
|
||||
std::string description,
|
||||
std::vector<operation_option> options = {},
|
||||
std::vector<operation_option> positional_options = {})
|
||||
: _name(std::move(name))
|
||||
std::vector<operation_option> positional_options = {},
|
||||
std::vector<operation> suboperations = {})
|
||||
: _name({std::move(name)})
|
||||
, _aliases(std::move(aliases))
|
||||
, _summary(std::move(summary))
|
||||
, _description(std::move(description))
|
||||
, _options(std::move(options))
|
||||
, _positional_options(std::move(positional_options)) {
|
||||
, _positional_options(std::move(positional_options))
|
||||
, _suboperations(std::move(suboperations)) {
|
||||
for (auto& op: _suboperations) {
|
||||
op.set_superoperation_name(_name[0]);
|
||||
}
|
||||
}
|
||||
|
||||
operation(
|
||||
@@ -111,19 +116,29 @@ public:
|
||||
std::string summary,
|
||||
std::string description,
|
||||
std::vector<operation_option> options = {},
|
||||
std::vector<operation_option> positional_options = {})
|
||||
: operation(std::move(name), {}, std::move(summary), std::move(description), std::move(options), std::move(positional_options))
|
||||
std::vector<operation_option> positional_options = {},
|
||||
std::vector<operation> suboperations = {})
|
||||
: operation(std::move(name), {}, std::move(summary), std::move(description), std::move(options), std::move(positional_options), std::move(suboperations))
|
||||
{}
|
||||
|
||||
const std::string& name() const { return _name; }
|
||||
const std::string& name() const { return _name[0]; }
|
||||
const std::vector<std::string>& fullname() const { return _name; }
|
||||
const std::vector<std::string>& aliases() const { return _aliases; }
|
||||
const std::string& summary() const { return _summary; }
|
||||
const std::string& description() const { return _description; }
|
||||
const std::vector<operation_option>& options() const { return _options; }
|
||||
const std::vector<operation_option>& positional_options() const { return _positional_options; }
|
||||
const std::vector<operation>& suboperations() const { return _suboperations; }
|
||||
|
||||
// Does the name or any of the aliases matches the provided name?
|
||||
bool matches(std::string_view name) const;
|
||||
private:
|
||||
void set_superoperation_name(std::string& name) {
|
||||
_name.push_back(name);
|
||||
for (auto& op: _suboperations) {
|
||||
op.set_superoperation_name(name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator<(const operation& a, const operation& b) {
|
||||
|
||||
Reference in New Issue
Block a user