| /* | |
| * Copyright (c) 2024 Project CHIP Authors | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| #pragma once | |
| #include <lib/shell/Command.h> | |
| #include <lib/support/Span.h> | |
| namespace chip { | |
| namespace Shell { | |
| /** | |
| * Shell command set. | |
| * | |
| * The shell command set is a thin wrapper for the span of commands. | |
| * It facilitates executing a matching shell command for the given input arguments. | |
| */ | |
| class CommandSet | |
| { | |
| public: | |
| template <size_t N> | |
| constexpr CommandSet(const Command (&commands)[N]) : mCommands(commands) | |
| {} | |
| /** | |
| * Dispatch and execute the command for the given argument list. | |
| * | |
| * The first argument is used to select the command to be executed and | |
| * the remaining arguments are forwarded to the command's handler. | |
| * If no argument has been provided or the first argument is "help", then | |
| * the function prints help text for each command and returns no error. | |
| * | |
| * @param argc Number of arguments in argv. | |
| * @param argv Array of arguments in the tokenized command line to execute. | |
| */ | |
| CHIP_ERROR ExecCommand(int argc, char * argv[]) const; | |
| private: | |
| void ShowHelp() const; | |
| Span<const Command> mCommands; | |
| }; | |
| } // namespace Shell | |
| } // namespace chip |