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 "pasteboard_dump_helper.h"
17
18 namespace OHOS {
19 namespace MiscServices {
Dump(int fd,const std::vector<std::string> & args) const20 bool PasteboardDumpHelper::Dump(int fd, const std::vector<std::string> &args) const
21 {
22 dprintf(fd, "\n---------------------------------\n");
23 if (args.empty() || args.at(0) == "-h") {
24 printf("\n%-15s: %-20s", "Option", "Description");
25 for (auto &[key, handler] : cmdHandler) {
26 dprintf(fd, "\n%-15s: %-20s\n", handler->GetFormat().c_str(), handler->ShowHelp().c_str());
27 }
28 return false;
29 }
30 auto handler = cmdHandler.find(args.at(0));
31 if (handler != cmdHandler.end()) {
32 std::string output;
33 handler->second->DoAction(args, output);
34 dprintf(fd, "%s\n", output.c_str());
35 return true;
36 }
37 return false;
38 }
RegisterCommand(std::shared_ptr<Command> & cmd)39 void PasteboardDumpHelper::RegisterCommand(std::shared_ptr<Command> &cmd)
40 {
41 cmdHandler.insert(std::make_pair(cmd->GetOption(), cmd));
42 }
43
GetInstance()44 PasteboardDumpHelper &PasteboardDumpHelper::GetInstance()
45 {
46 static PasteboardDumpHelper instance;
47 return instance;
48 }
49 } // namespace MiscServices
50 } // namespace OHOS
51