Support for localized descriptions

This commit is contained in:
Uwe Seimet 2021-12-17 18:29:22 +01:00
parent b4ff4f52ab
commit d3af9a142c
3 changed files with 28 additions and 11 deletions

View File

@ -162,8 +162,8 @@ enum PbOperation {
// The operation parameter meta data
message PbOperationParameter {
string name = 1;
// Optional description
string description = 2;
// Optional short localized description, key is the lower case locale (e.g. en, de)
map<string, string> description = 2;
// "int" or "string"
string type = 3;
// There is no specific set of values if empty
@ -174,8 +174,8 @@ message PbOperationParameter {
// The list of parameters supported by an operation
message PbOperationParameters {
string operation = 1;
// Optional description
string description = 2;
// Optional short localized description, key is the lower case locale (e.g. en, de)
map<string, string> description = 2;
repeated PbOperationParameter parameters = 3;
}

View File

@ -344,16 +344,33 @@ PbOperationInfo *RascsiResponse::GetOperationInfo(PbResult& result)
parameters = operation_info->add_operations();
parameters->set_operation(PbOperation_Name(ATTACH));
parameters->set_description("Attach device, one of the parameters below is required");
(*parameters->mutable_description())["en"] = "Attach device, one of the parameters below is required";
parameter = parameters->add_parameters();
parameter->set_name("name");
parameter->set_description("Image file name");
(*parameter->mutable_description())["en"] = "Image file name";
parameter->set_type("string");
parameter = parameters->add_parameters();
parameter->set_name("interfaces");
parameter->set_description("Comma-separated list of network interfaces");
(*parameter->mutable_description())["en"] = "Comma-separated list of network interfaces";
parameter->set_type("string");
parameters = operation_info->add_operations();
parameters->set_operation(PbOperation_Name(DETACH));
(*parameters->mutable_description())["en"] = "Detach device";
parameters = operation_info->add_operations();
parameters->set_operation(PbOperation_Name(DETACH_ALL));
(*parameters->mutable_description())["en"] = "Detach all devices";
parameters = operation_info->add_operations();
parameters->set_operation(PbOperation_Name(START));
(*parameters->mutable_description())["en"] = "Start device";
parameters = operation_info->add_operations();
parameters->set_operation(PbOperation_Name(STOP));
(*parameters->mutable_description())["en"] = "Stop device";
parameters = operation_info->add_operations();
parameters->set_operation(PbOperation_Name(OPERATION_INFO));

View File

@ -277,18 +277,18 @@ void RasctlDisplay::DisplayMappingInfo(const PbMappingInfo& mapping_info)
void RasctlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info)
{
cout << "Remote operations supported by rascsi and their parameters:" << endl;
for (const auto& operation : operation_info.operations()) {
for (auto& operation : operation_info.operations()) {
cout << " " << operation.operation();
if (!operation.description().empty()) {
cout << " (" << operation.description() << ")";
cout << " (" << operation.description().at("en") << ")";
}
cout << endl;
for (const auto& parameter : operation.parameters()) {
for (auto& parameter : operation.parameters()) {
cout << " " << parameter.name() << ": " << parameter.type()
<< (parameter.is_mandatory() ? ", mandatory" : ", optional");
if (!parameter.description().empty()) {
cout << " (" << parameter.description() << ")";
cout << " (" << parameter.description().at("en") << ")";
}
cout << endl;
}