1 /*
2 * Copyright (c) 2021-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 * miscservices under the License is miscservices 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 ScreenLock {
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) : format(argsFormat), help(help)
26 {
27 }
28
ShowHelp()29 std::string Command::ShowHelp()
30 {
31 return help;
32 }
33
DoAction(const std::vector<std::string> & input,std::string & output)34 bool Command::DoAction(const std::vector<std::string> &input, std::string &output)
35 {
36 return action(input, output);
37 }
38
GetOption()39 std::string Command::GetOption()
40 {
41 return format.at(0);
42 }
43
GetFormat()44 std::string Command::GetFormat()
45 {
46 std::string formatStr;
47 for (const auto &seg : format) {
48 formatStr += seg;
49 formatStr += " ";
50 }
51 return formatStr;
52 }
53 } // namespace ScreenLock
54 } // namespace OHOS