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