From c88628e12ad252420f29ebed0541a1c3c4ede231 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Sat, 18 Dec 2021 14:17:50 +0100 Subject: [PATCH] Sort map by operation name --- src/raspberrypi/rasctl_display.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/raspberrypi/rasctl_display.cpp b/src/raspberrypi/rasctl_display.cpp index 022f3abb..5175aedb 100644 --- a/src/raspberrypi/rasctl_display.cpp +++ b/src/raspberrypi/rasctl_display.cpp @@ -276,13 +276,26 @@ void RasctlDisplay::DisplayMappingInfo(const PbMappingInfo& mapping_info) void RasctlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info) { - // Creates a sorted map const map operations = { operation_info.operations().begin(), operation_info.operations().end() }; + // Copies result into a map sorted by operation name + PbOperationMetaData *empty_operation = new PbOperationMetaData(); + map sorted_operations; + auto iter = operations.begin(); + while (iter != operations.end()) { + if (PbOperation_IsValid(static_cast(iter->first))) { + sorted_operations[PbOperation_Name(static_cast(iter->first))] = iter->second; + } + else { + sorted_operations[iter->second.name()] = *empty_operation; + } + iter++; + } + cout << "Remote operations supported by rascsi and their parameters:" << endl; - for (const auto& operation : operations) { - if (PbOperation_IsValid(static_cast(operation.first))) { - cout << " " << PbOperation_Name(static_cast(operation.first)); + for (const auto& operation : sorted_operations) { + if (!operation.second.name().empty()) { + cout << " " << operation.first; if (!operation.second.description().empty()) { cout << " (" << operation.second.description().at("en") << ")"; } @@ -315,7 +328,7 @@ void RasctlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info) } } else { - cout << " " << operation.second.name() << " (Unknown server-side operation)" << endl; + cout << " " << operation.first << " (Unknown server-side operation)" << endl; } } }