1 /*
2 * Copyright (C) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "command.h"
17
18 namespace OHOS {
19 namespace MiscServices {
Command(const std::vector<std::string> & argsFormat,const std::string & help,const Command::Action & action)20 Command::Command(const std::vector<std::string> &argsFormat, const std::string &help, const Command::Action &action)
21 : format_(argsFormat), help_(help), action_(action)
22 {
23 }
24
Command(const std::vector<std::string> & argsFormat,const std::string & help)25 Command::Command(const std::vector<std::string> &argsFormat, const std::string &help)
26 : format_(argsFormat), help_(help)
27 {
28 }
29
ShowHelp()30 std::string Command::ShowHelp()
31 {
32 return help_;
33 }
34
DoAction(const std::vector<std::string> & input,std::string & output)35 bool Command::DoAction(const std::vector<std::string> &input, std::string &output)
36 {
37 return action_(input, output);
38 }
39
GetOption()40 std::string Command::GetOption()
41 {
42 return format_.at(0);
43 }
44
GetFormat()45 std::string Command::GetFormat()
46 {
47 std::string formatStr;
48 for (auto &seg : format_) {
49 formatStr += seg;
50 formatStr += " ";
51 }
52 return formatStr;
53 }
54 } // namespace MiscServices
55 } // namespace OHOS