From abb10fb5a1e0ce3a1e42d4ce86b9ea6860b9353e Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sat, 25 Mar 2023 09:51:27 -0400 Subject: [PATCH] Show command help text in chip-tool cluster listings. (#25825) Also adds help text for the close-session command. --- examples/chip-tool/commands/common/Commands.cpp | 17 +++++++++++++++++ .../commands/pairing/CloseSessionCommand.h | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/commands/common/Commands.cpp b/examples/chip-tool/commands/common/Commands.cpp index 1276e4a624220b..8e9aa8d59c1cdc 100644 --- a/examples/chip-tool/commands/common/Commands.cpp +++ b/examples/chip-tool/commands/common/Commands.cpp @@ -399,6 +399,23 @@ void Commands::ShowCluster(std::string executable, std::string clusterName, Comm if (shouldPrint) { fprintf(stderr, " | * %-82s|\n", command->GetName()); + const char * helpText = command->GetHelpText(); + if (command->GetHelpText()) + { + // We leave 82 chars for command names. The help text starts + // two chars further to the right, so there are 80 chars left + // for it. + if (strlen(helpText) > 80) + { + // Add "..." at the end to indicate truncation, and only + // show the first 77 chars, since that's what will fit. + fprintf(stderr, " | - %.77s...|\n", helpText); + } + else + { + fprintf(stderr, " | - %-80s|\n", helpText); + } + } } } fprintf(stderr, " +-------------------------------------------------------------------------------------+\n"); diff --git a/examples/chip-tool/commands/pairing/CloseSessionCommand.h b/examples/chip-tool/commands/pairing/CloseSessionCommand.h index ba8f8c863eeeca..edbcb82b094d5d 100644 --- a/examples/chip-tool/commands/pairing/CloseSessionCommand.h +++ b/examples/chip-tool/commands/pairing/CloseSessionCommand.h @@ -27,8 +27,8 @@ class CloseSessionCommand : public CHIPCommand { public: CloseSessionCommand(CredentialIssuerCommands * credIssuerCommands) : - CHIPCommand("close-session", credIssuerCommands), mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), - mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this) + CHIPCommand("close-session", credIssuerCommands, "Sends a CloseSession message to the given destination node id."), + mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this) { AddArgument("destination-id", 0, UINT64_MAX, &mDestinationId); AddArgument("timeout", 0, UINT64_MAX, &mTimeoutSecs,