1 /*
2  * Copyright (c) 2022-2022 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 #include "command.h"
16 namespace OHOS {
17 namespace MiscServices {
Command(const std::vector<std::string> & argsFormat,const std::string & help,const Command::Action & action)18 Command::Command(const std::vector<std::string> &argsFormat, const std::string &help, const Command::Action &action)
19     : format_(argsFormat), help_(help), action_(action)
20 {
21 }
22 
ShowHelp() const23 std::string Command::ShowHelp() const
24 {
25     return help_;
26 }
27 
DoAction(const std::vector<std::string> & input,std::string & output)28 bool Command::DoAction(const std::vector<std::string> &input, std::string &output)
29 {
30     return action_(input, output);
31 }
32 
GetOption()33 std::string Command::GetOption()
34 {
35     return format_.at(0);
36 }
37 
GetFormat()38 std::string Command::GetFormat()
39 {
40     std::string formatStr;
41     for (const auto &seg : format_) {
42         formatStr += seg;
43         formatStr += " ";
44     }
45     return formatStr;
46 }
47 } // namespace MiscServices
48 } // namespace OHOS
49