From db117e27b20880b105f6905f8d557a873ea0b782 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 9 Feb 2021 22:14:48 -0800 Subject: [PATCH] [cli] add helper method to output "Enabled/Disabled" status (#6158) --- src/cli/cli.cpp | 34 +++++++++------------------------- src/cli/cli.hpp | 8 ++++++++ src/cli/cli_srp_client.cpp | 2 +- src/cli/cli_udp.cpp | 2 +- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index a9df10f92..21d876999 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -189,6 +189,11 @@ void Interpreter::OutputBytes(const uint8_t *aBytes, uint16_t aLength) } } +void Interpreter::OutputEnabledDisabledStatus(bool aEnabled) +{ + OutputLine(aEnabled ? "Enabled" : "Disabled"); +} + int Interpreter::OutputIp6Address(const otIp6Address &aAddress) { return OutputFormat( @@ -1083,7 +1088,7 @@ otError Interpreter::ProcessCoexMetrics(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - OutputLine(otPlatRadioIsCoexEnabled(mInstance) ? "Enabled" : "Disabled"); + OutputEnabledDisabledStatus(otPlatRadioIsCoexEnabled(mInstance)); } else if (strcmp(aArgs[0], "enable") == 0) { @@ -1792,14 +1797,7 @@ otError Interpreter::ProcessMulticastPromiscuous(uint8_t aArgsLength, char *aArg if (aArgsLength == 0) { - if (otIp6IsMulticastPromiscuousEnabled(mInstance)) - { - OutputLine("Enabled"); - } - else - { - OutputLine("Disabled"); - } + OutputEnabledDisabledStatus(otIp6IsMulticastPromiscuousEnabled(mInstance)); } else { @@ -3062,14 +3060,7 @@ otError Interpreter::ProcessPromiscuous(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - if (otLinkIsPromiscuous(mInstance) && otPlatRadioGetPromiscuous(mInstance)) - { - OutputLine("Enabled"); - } - else - { - OutputLine("Disabled"); - } + OutputEnabledDisabledStatus(otLinkIsPromiscuous(mInstance) && otPlatRadioGetPromiscuous(mInstance)); } else { @@ -3616,14 +3607,7 @@ otError Interpreter::ProcessRouterEligible(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - if (otThreadIsRouterEligible(mInstance)) - { - OutputLine("Enabled"); - } - else - { - OutputLine("Disabled"); - } + OutputEnabledDisabledStatus(otThreadIsRouterEligible(mInstance)); } else if (strcmp(aArgs[0], "enable") == 0) { diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 8cc2abf69..386d98ea0 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -258,6 +258,14 @@ public: */ void OutputResult(otError aError); + /** + * This method delivers "Enabled" or "Disabled" status to the CLI client (it also appends newline `\r\n`). + * + * @param[in] aEnabled A boolean indicating the status. TRUE outputs "Enabled", FALSE outputs "Disabled". + * + */ + void OutputEnabledDisabledStatus(bool aEnabled); + /** * This method sets the user command table. * diff --git a/src/cli/cli_srp_client.cpp b/src/cli/cli_srp_client.cpp index 332fa9dbe..c57d82a91 100644 --- a/src/cli/cli_srp_client.cpp +++ b/src/cli/cli_srp_client.cpp @@ -102,7 +102,7 @@ otError SrpClient::ProcessCallback(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mInterpreter.OutputLine(mCallbackEnabled ? "Enabled" : "Disabled"); + mInterpreter.OutputEnabledDisabledStatus(mCallbackEnabled); ExitNow(); } diff --git a/src/cli/cli_udp.cpp b/src/cli/cli_udp.cpp index 501d29aab..136df3669 100644 --- a/src/cli/cli_udp.cpp +++ b/src/cli/cli_udp.cpp @@ -214,7 +214,7 @@ otError UdpExample::ProcessLinkSecurity(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength == 0) { - mInterpreter.OutputLine(mLinkSecurityEnabled ? "Enabled" : "Disabled"); + mInterpreter.OutputEnabledDisabledStatus(mLinkSecurityEnabled); } else if (strcmp(aArgs[0], "enable") == 0) {