• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <iostream>
17 #include <sstream>
18 
19 #include "tools_op.h"
20 
21 namespace OHOS::FileManagement::Backup {
22 using namespace std;
23 
GenHelpMsg()24 static string GenHelpMsg()
25 {
26     return "\t\tThis operation helps to dump the help messages.";
27 }
28 
Exec(map<string,vector<string>> & mapArgToVal)29 static int Exec(map<string, vector<string>> &mapArgToVal)
30 {
31     stringstream ss;
32     auto &&allOps = ToolsOp::GetAllOperations();
33     ss << "Usage: backup_tool <SubCommand> [OPTION]... [ARG]..." << endl;
34     for (size_t i = 0; i < allOps.size(); ++i) {
35         auto desc = allOps[i].GetDescriptor();
36 
37         // echo: <op seqs>\n
38         ss << allOps[i].GetName();
39 
40         // echo: help msgs\n\n
41         if (desc.funcGenHelpMsg) {
42             ss << desc.funcGenHelpMsg() << endl;
43         }
44         if (i != allOps.size() - 1) {
45             ss << endl;
46         }
47     }
48     printf("%s", ss.str().c_str());
49     return 0;
50 }
51 
52 /**
53  * @brief The hack behind is that "variable with static storage duration has initialization or a destructor with side
54  * effects; it shall not be eliminated even if it appears to be unused" -- point 2.[basic.stc.static].c++ draft
55  *
56  */
57 static bool g_autoRegHack = ToolsOp::Register(ToolsOp {ToolsOp::Descriptor {
58     .opName = {"help"},
59     .funcGenHelpMsg = GenHelpMsg,
60     .funcExec = Exec,
61 }});
62 } // namespace OHOS::FileManagement::Backup