1 /* 2 * Copyright (c) 2024-2024 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 "cmd/dump_parser.h" 17 #include <memory> 18 #include <string> 19 #include "cmd/cmd_parser.h" 20 #include "resource_util.h" 21 #include "resource_dumper.h" 22 23 namespace OHOS { 24 namespace Global { 25 namespace Restool { 26 using namespace std; ParseOption(int argc,char * argv[],int currentIndex)27uint32_t DumpParserBase::ParseOption(int argc, char *argv[], int currentIndex) 28 { 29 if (currentIndex >= argc || currentIndex < 0) { 30 PrintError(ERR_CODE_DUMP_MISSING_INPUT); 31 return RESTOOL_ERROR; 32 } 33 inputPath_ = ResourceUtil::RealPath(argv[currentIndex]); 34 if (inputPath_.empty()) { 35 PrintError(GetError(ERR_CODE_DUMP_INVALID_INPUT).FormatCause(argv[currentIndex])); 36 return RESTOOL_ERROR; 37 } 38 return RESTOOL_SUCCESS; 39 } 40 GetInputPath() const41const string& DumpParserBase::GetInputPath() const 42 { 43 return inputPath_; 44 } 45 DumpParser()46DumpParser::DumpParser() : CmdParserBase("dump") 47 { 48 subcommands_.emplace_back(std::make_unique<DumpConfigParser>()); 49 } 50 ExecCommand()51uint32_t DumpParser::ExecCommand() 52 { 53 return CommonDumper().Dump(*this); 54 } 55 ShowUseage()56void DumpParserBase::ShowUseage() 57 { 58 std::cout << "Usage:\n"; 59 std::cout << "restool dump [subcommand] [options] file.\n"; 60 std::cout << "[subcommands]:\n"; 61 std::cout << " config Print config of the resource in the hap.\n"; 62 std::cout << "\n"; 63 std::cout << "[options]:\n"; 64 std::cout << " -h Print dump subcommand help info.\n"; 65 } 66 DumpConfigParser()67DumpConfigParser::DumpConfigParser() : CmdParserBase("config") 68 {} 69 ExecCommand()70uint32_t DumpConfigParser::ExecCommand() 71 { 72 return ConfigDumper().Dump(*this); 73 } 74 } // namespace Restool 75 } // namespace Global 76 } // namespace OHOS