1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License. 5eace7efcSopenharmony_ci * You may obtain a copy of the License at 6eace7efcSopenharmony_ci * 7eace7efcSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8eace7efcSopenharmony_ci * 9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and 13eace7efcSopenharmony_ci * limitations under the License. 14eace7efcSopenharmony_ci */ 15eace7efcSopenharmony_ci 16eace7efcSopenharmony_ci#ifndef OHOS_ABILITY_RUNTIME_SHELL_COMMAND_H 17eace7efcSopenharmony_ci#define OHOS_ABILITY_RUNTIME_SHELL_COMMAND_H 18eace7efcSopenharmony_ci 19eace7efcSopenharmony_ci#include <map> 20eace7efcSopenharmony_ci#include <string> 21eace7efcSopenharmony_ci#include <functional> 22eace7efcSopenharmony_ci#include <vector> 23eace7efcSopenharmony_ci 24eace7efcSopenharmony_ci#include "errors.h" 25eace7efcSopenharmony_ci 26eace7efcSopenharmony_cinamespace OHOS { 27eace7efcSopenharmony_cinamespace AAFwk { 28eace7efcSopenharmony_cinamespace { 29eace7efcSopenharmony_ciconst std::string HELP_MSG_NO_OPTION = "error: you must specify an option at least."; 30eace7efcSopenharmony_ci 31eace7efcSopenharmony_ciconst int OFFSET_REQUIRED_ARGUMENT = 2; 32eace7efcSopenharmony_ci} // namespace 33eace7efcSopenharmony_ci 34eace7efcSopenharmony_ciclass ShellCommand { 35eace7efcSopenharmony_cipublic: 36eace7efcSopenharmony_ci ShellCommand(int argc, char* argv[], std::string name); 37eace7efcSopenharmony_ci virtual ~ShellCommand(); 38eace7efcSopenharmony_ci 39eace7efcSopenharmony_ci ErrCode OnCommand(); 40eace7efcSopenharmony_ci std::string ExecCommand(); 41eace7efcSopenharmony_ci std::string GetCommandErrorMsg() const; 42eace7efcSopenharmony_ci std::string GetUnknownOptionMsg(std::string& unknownOption) const; 43eace7efcSopenharmony_ci std::string GetMessageFromCode(const int32_t code) const; 44eace7efcSopenharmony_ci 45eace7efcSopenharmony_ci virtual ErrCode CreateCommandMap() = 0; 46eace7efcSopenharmony_ci virtual ErrCode CreateMessageMap() = 0; 47eace7efcSopenharmony_ci virtual ErrCode init() = 0; 48eace7efcSopenharmony_ci 49eace7efcSopenharmony_ciprotected: 50eace7efcSopenharmony_ci static constexpr int MIN_ARGUMENT_NUMBER = 2; 51eace7efcSopenharmony_ci static constexpr int MAX_ARGUMENT_NUMBER = 4096; 52eace7efcSopenharmony_ci 53eace7efcSopenharmony_ci int argc_ = 0; 54eace7efcSopenharmony_ci char** argv_ = nullptr; 55eace7efcSopenharmony_ci 56eace7efcSopenharmony_ci std::string cmd_; 57eace7efcSopenharmony_ci std::vector<std::string> argList_; 58eace7efcSopenharmony_ci 59eace7efcSopenharmony_ci std::string name_; 60eace7efcSopenharmony_ci std::map<std::string, std::function<int()>> commandMap_; 61eace7efcSopenharmony_ci std::map<int32_t, std::string> messageMap_; 62eace7efcSopenharmony_ci 63eace7efcSopenharmony_ci std::string resultReceiver_ = ""; 64eace7efcSopenharmony_ci}; 65eace7efcSopenharmony_ci} // namespace AAFwk 66eace7efcSopenharmony_ci} // namespace OHOS 67eace7efcSopenharmony_ci 68eace7efcSopenharmony_ci#endif // OHOS_ABILITY_RUNTIME_SHELL_COMMAND_H 69