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
16 #include "time_cmd_parse.h"
17
TimeCmdParse(const std::vector<std::string> & argsFormat,const std::string & strHelp,const TimeCmdParse::Action & action)18 TimeCmdParse::TimeCmdParse(
19 const std::vector<std::string> &argsFormat, const std::string &strHelp, const TimeCmdParse::Action &action)
20 : format(argsFormat), help(strHelp), action(action)
21 {
22 }
ShowHelp()23 std::string TimeCmdParse::ShowHelp()
24 {
25 return help;
26 }
27
DoAction(int fd,const std::vector<std::string> & input)28 void TimeCmdParse::DoAction(int fd, const std::vector<std::string> &input)
29 {
30 action(fd, input);
31 }
32
GetOption()33 std::string TimeCmdParse::GetOption()
34 {
35 std::string formatTitle;
36 for (unsigned long i = 0; i < format.size() - 1; i++) {
37 formatTitle += format.at(i);
38 formatTitle += " ";
39 }
40 return formatTitle.substr(0, formatTitle.length() - 1);
41 }
42
GetFormat()43 std::string TimeCmdParse::GetFormat()
44 {
45 std::string formatStr;
46 for (auto &seg : format) {
47 formatStr += seg;
48 formatStr += " ";
49 }
50 return formatStr;
51 }