diff --git a/vpd-tool/src/vpd_tool.cpp b/vpd-tool/src/vpd_tool.cpp index e9ce2cf3..71e9a105 100644 --- a/vpd-tool/src/vpd_tool.cpp +++ b/vpd-tool/src/vpd_tool.cpp @@ -1011,38 +1011,14 @@ int VpdTool::handleMoreOption( "source path information is missing in JSON"); } - auto updateKeywordValue = - [](std::string io_vpdPath, const std::string& i_recordName, - const std::string& i_keywordName, - const types::BinaryVector& i_keywordValue) -> int { - int l_rc = constants::FAILURE; + int l_slNum = 0; - try - { - auto l_paramsToWrite = std::make_tuple( - i_recordName, i_keywordName, i_keywordValue); - l_rc = utils::writeKeyword(io_vpdPath, l_paramsToWrite); - - if (l_rc > 0) - { - std::cout << std::endl - << "Data updated successfully." << std::endl; - } - } - catch (const std::exception& l_ex) - { - // TODO: Enable log when verbose is enabled. - std::cerr << l_ex.what() << std::endl; - } - return l_rc; - }; - - do + for (const auto& l_aRecordKwInfo : i_parsedJsonObj["backupMap"]) { - int l_slNum = 0; - bool l_exit = false; + l_rc = constants::SUCCESS; + ++l_slNum; - for (const auto& l_aRecordKwInfo : i_parsedJsonObj["backupMap"]) + while (true) { if (!l_aRecordKwInfo.contains("sourceRecord") || !l_aRecordKwInfo.contains("sourceKeyword") || @@ -1053,9 +1029,11 @@ int VpdTool::handleMoreOption( std::cerr << "Source or destination information is missing in the JSON." << std::endl; - continue; + break; } + bool l_exitLoop = true; + const std::string l_mismatchFound{ (l_aRecordKwInfo["sourcekeywordValue"] != l_aRecordKwInfo["destinationkeywordValue"]) @@ -1072,7 +1050,7 @@ int VpdTool::handleMoreOption( << "Data Mismatch" << std::endl; std::cout << std::left << std::setw(6) - << static_cast(++l_slNum) << std::left + << static_cast(l_slNum) << std::left << std::setw(8) << l_aRecordKwInfo.value("sourceRecord", "") << std::left << std::setw(9) @@ -1101,6 +1079,7 @@ int VpdTool::handleMoreOption( } else { + std::cout << "No mismatch found." << std::endl << std::endl; printFixSystemVpdOption(types::UserOption::NewValueOnBoth); printFixSystemVpdOption(types::UserOption::SkipCurrent); printFixSystemVpdOption(types::UserOption::Exit); @@ -1109,74 +1088,112 @@ int VpdTool::handleMoreOption( int l_userSelectedOption = types::UserOption::Exit; std::cin >> l_userSelectedOption; - if (types::UserOption::UseBackupDataForCurrent == - l_userSelectedOption) - { - l_rc = updateKeywordValue( - l_srcVpdPath, l_aRecordKwInfo["sourceRecord"], - l_aRecordKwInfo["sourceKeyword"], - l_aRecordKwInfo["destinationkeywordValue"]); - } - else if (types::UserOption::UseSystemBackplaneDataForCurrent == - l_userSelectedOption) + switch (l_userSelectedOption) { - l_rc = updateKeywordValue( - l_srcVpdPath, l_aRecordKwInfo["sourceRecord"], - l_aRecordKwInfo["sourceKeyword"], - l_aRecordKwInfo["sourcekeywordValue"]); - } - else if (types::UserOption::NewValueOnBoth == - l_userSelectedOption) - { - std::string l_newValue; - std::cout - << std::endl - << "Enter the new value to update on both " - "primary & backup. Value should be in ASCII or " - "in HEX(prefixed with 0x) : "; - std::cin >> l_newValue; - std::cout << std::endl - << std::string(191, '=') << std::endl; - - try - { - l_rc = updateKeywordValue( - l_srcVpdPath, l_aRecordKwInfo["sourceRecord"], - l_aRecordKwInfo["sourceKeyword"], - utils::convertToBinary(l_newValue)); - } - catch (const std::exception& l_ex) + case types::UserOption::UseBackupDataForCurrent: + try + { + l_rc = utils::writeKeyword( + l_srcVpdPath, + std::make_tuple( + l_aRecordKwInfo["sourceRecord"], + l_aRecordKwInfo["sourceKeyword"], + l_aRecordKwInfo + ["destinationkeywordValue"])); + + if (l_rc > 0) + { + std::cout << std::endl + << "Data updated successfully." + << std::endl; + } + } + catch (const std::exception& l_ex) + { + // TODO: Enable log when verbose is enabled. + std::cerr << l_ex.what() << std::endl; + } + break; + case types::UserOption::UseSystemBackplaneDataForCurrent: + try + { + l_rc = utils::writeKeyword( + l_srcVpdPath, + std::make_tuple( + l_aRecordKwInfo["sourceRecord"], + l_aRecordKwInfo["sourceKeyword"], + l_aRecordKwInfo["sourcekeywordValue"])); + + if (l_rc > 0) + { + std::cout << std::endl + << "Data updated successfully." + << std::endl; + } + } + catch (const std::exception& l_ex) + { + // TODO: Enable log when verbose is enabled. + std::cerr << l_ex.what() << std::endl; + } + break; + case types::UserOption::NewValueOnBoth: { - // TODO: Enable logging when verbose is enabled. - std::cerr << l_ex.what() << std::endl; + std::string l_newValue; + std::cout + << std::endl + << "Enter the new value to update on both " + "primary & backup. Value should be in ASCII or " + "in HEX(prefixed with 0x) : "; + std::cin >> l_newValue; + std::cout << std::endl + << std::string(191, '=') << std::endl; + + try + { + l_rc = utils::writeKeyword( + l_srcVpdPath, + std::make_tuple( + l_aRecordKwInfo["sourceRecord"], + l_aRecordKwInfo["sourceKeyword"], + utils::convertToBinary(l_newValue))); + + if (l_rc > 0) + { + std::cout << std::endl + << "Data updated successfully." + << std::endl; + } + } + catch (const std::exception& l_ex) + { + // TODO: Enable logging when verbose is enabled. + std::cerr << l_ex.what() << std::endl; + } + break; } - } - else if (types::UserOption::SkipCurrent == l_userSelectedOption) - { - std::cout << std::endl - << "Skipped the above record-keyword pair. " - "Continue to the next available pair." - << std::endl; - } - else if (types::UserOption::Exit == l_userSelectedOption) + case types::UserOption::SkipCurrent: + std::cout << std::endl + << "Skipped the above record-keyword pair. " + "Continue to the next available pair." + << std::endl; + break; + case types::UserOption::Exit: + std::cout << "Exit successfully" << std::endl; + return constants::SUCCESS; + default: + l_exitLoop = false; + std::cout << "Provide a valid option. Retrying for the " + "current record-keyword pair" + << std::endl; + } // end switch + + if (l_exitLoop) { - std::cout << "Exit successfully" << std::endl; - l_exit = true; break; } - else - { - std::cout << "Provide a valid option. Retrying for the " - "current record-keyword pair" - << std::endl; - } - } - if (l_exit) - { - l_rc = constants::SUCCESS; - break; - } - } while (true); + } // end while + } // end for } catch (const std::exception& l_ex) {