diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp index 0eeeb3a85f9edd..ad474039d07f65 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp +++ b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp @@ -26,7 +26,12 @@ void DiscoverCommissionablesCommandBase::OnDiscoveredDevice(const chip::Dnssd::D { nodeData.LogDetail(); LogErrorOnFailure(RemoteDataModelLogger::LogDiscoveredNodeData(nodeData)); - SetCommandExitStatus(CHIP_NO_ERROR); + + if (mDiscoverOnce.ValueOr(true)) + { + CurrentCommissioner().StopCommissionableDiscovery(); + SetCommandExitStatus(CHIP_NO_ERROR); + } } CHIP_ERROR DiscoverCommissionablesCommand::RunCommand() diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h index 58ee5a0500ba1d..b0bff0e4e113e0 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h +++ b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h @@ -25,13 +25,19 @@ class DiscoverCommissionablesCommandBase : public CHIPCommand, public chip::Cont public: DiscoverCommissionablesCommandBase(const char * name, CredentialIssuerCommands * credsIssuerConfig) : CHIPCommand(name, credsIssuerConfig) - {} + { + AddArgument("discover-once", 0, 1, &mDiscoverOnce, + "Boolean indicating whether to stop discovery after the first result. Defaults to true."); + } /////////// DeviceDiscoveryDelegate Interface ///////// void OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) override; /////////// CHIPCommand Interface ///////// chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(30); } + +private: + chip::Optional mDiscoverOnce; }; class DiscoverCommissionablesCommand : public DiscoverCommissionablesCommandBase