1545fdf9bSopenharmony_ci/*
2545fdf9bSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3545fdf9bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4545fdf9bSopenharmony_ci * you may not use this file except in compliance with the License.
5545fdf9bSopenharmony_ci * You may obtain a copy of the License at
6545fdf9bSopenharmony_ci *
7545fdf9bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8545fdf9bSopenharmony_ci *
9545fdf9bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10545fdf9bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11545fdf9bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12545fdf9bSopenharmony_ci * See the License for the specific language governing permissions and
13545fdf9bSopenharmony_ci * limitations under the License.
14545fdf9bSopenharmony_ci */
15545fdf9bSopenharmony_ci
16545fdf9bSopenharmony_ci#ifndef FOUNDATION_APPEXECFWK_STANDARD_TOOLS_BM_INCLUDE_SHELL_COMMAND_H
17545fdf9bSopenharmony_ci#define FOUNDATION_APPEXECFWK_STANDARD_TOOLS_BM_INCLUDE_SHELL_COMMAND_H
18545fdf9bSopenharmony_ci
19545fdf9bSopenharmony_ci#include <map>
20545fdf9bSopenharmony_ci#include <string>
21545fdf9bSopenharmony_ci#include <functional>
22545fdf9bSopenharmony_ci#include <vector>
23545fdf9bSopenharmony_ci
24545fdf9bSopenharmony_ci#include "errors.h"
25545fdf9bSopenharmony_ci
26545fdf9bSopenharmony_cinamespace OHOS {
27545fdf9bSopenharmony_cinamespace AppExecFwk {
28545fdf9bSopenharmony_cinamespace {
29545fdf9bSopenharmony_ciconst std::string HELP_MSG_NO_OPTION = "error: you must specify an option at least.";
30545fdf9bSopenharmony_ciconst std::string STRING_CODE = "code:";
31545fdf9bSopenharmony_ciconst int OFFSET_REQUIRED_ARGUMENT = 2;
32545fdf9bSopenharmony_ci}  // namespace
33545fdf9bSopenharmony_ci
34545fdf9bSopenharmony_ciclass ShellCommand {
35545fdf9bSopenharmony_cipublic:
36545fdf9bSopenharmony_ci    ShellCommand(int argc, char *argv[], std::string name);
37545fdf9bSopenharmony_ci    virtual ~ShellCommand();
38545fdf9bSopenharmony_ci
39545fdf9bSopenharmony_ci    ErrCode OnCommand();
40545fdf9bSopenharmony_ci    std::string ExecCommand();
41545fdf9bSopenharmony_ci    std::string GetCommandErrorMsg() const;
42545fdf9bSopenharmony_ci    std::string GetUnknownOptionMsg(std::string &unknownOption) const;
43545fdf9bSopenharmony_ci    std::string GetMessageFromCode(const int32_t code) const;
44545fdf9bSopenharmony_ci
45545fdf9bSopenharmony_ci    virtual ErrCode CreateCommandMap() = 0;
46545fdf9bSopenharmony_ci    virtual ErrCode CreateMessageMap() = 0;
47545fdf9bSopenharmony_ci    virtual ErrCode Init() = 0;
48545fdf9bSopenharmony_ci
49545fdf9bSopenharmony_ciprotected:
50545fdf9bSopenharmony_ci    static constexpr int MIN_ARGUMENT_NUMBER = 2;
51545fdf9bSopenharmony_ci
52545fdf9bSopenharmony_ci    int argc_;
53545fdf9bSopenharmony_ci    char **argv_;
54545fdf9bSopenharmony_ci
55545fdf9bSopenharmony_ci    std::string cmd_;
56545fdf9bSopenharmony_ci    std::vector<std::string> argList_;
57545fdf9bSopenharmony_ci
58545fdf9bSopenharmony_ci    std::string name_;
59545fdf9bSopenharmony_ci    std::map<std::string, std::function<int()>> commandMap_;
60545fdf9bSopenharmony_ci    std::map<int32_t, std::string> messageMap_;
61545fdf9bSopenharmony_ci
62545fdf9bSopenharmony_ci    std::string resultReceiver_ = "";
63545fdf9bSopenharmony_ci};
64545fdf9bSopenharmony_ci
65545fdf9bSopenharmony_ci}  // namespace AppExecFwk
66545fdf9bSopenharmony_ci}  // namespace OHOS
67545fdf9bSopenharmony_ci
68545fdf9bSopenharmony_ci#endif  // FOUNDATION_APPEXECFWK_STANDARD_TOOLS_BM_INCLUDE_SHELL_COMMAND_H