From c606826acde542d268fd29114e446265bb639115 Mon Sep 17 00:00:00 2001 From: sunjie Date: Thu, 26 Dec 2024 10:31:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84dump=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunjie Change-Id: Ibbfa6a06b5dcb8385cf089f6695ab2c0a591dfe5 --- BUILD.gn | 1 + include/cmd/cmd_parser.h | 81 ++++++------------------ include/cmd/dump_parser.h | 28 ++++++--- include/cmd/package_parser.h | 13 ++-- include/resource_dumper.h | 9 +-- include/resource_merge.h | 4 +- src/cmd/cmd_parser.cpp | 118 +++++++++++++++++++++++++++++++++++ src/cmd/dump_parser.cpp | 53 +++++++++------- src/cmd/package_parser.cpp | 2 +- src/id_worker.cpp | 5 +- src/resource_dumper.cpp | 34 +++------- src/resource_table.cpp | 6 +- src/restool.cpp | 35 +++-------- src/select_compile_parse.cpp | 4 +- 14 files changed, 230 insertions(+), 163 deletions(-) create mode 100644 src/cmd/cmd_parser.cpp diff --git a/BUILD.gn b/BUILD.gn index f508195..9d1bd9a 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -19,6 +19,7 @@ ohos_executable("restool") { sources = [ "src/append_compiler.cpp", "src/binary_file_packer.cpp", + "src/cmd/cmd_parser.cpp", "src/cmd/dump_parser.cpp", "src/cmd/package_parser.cpp", "src/compression_parser.cpp", diff --git a/include/cmd/cmd_parser.h b/include/cmd/cmd_parser.h index 3bfa70a..b7b24a9 100644 --- a/include/cmd/cmd_parser.h +++ b/include/cmd/cmd_parser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 - 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,6 +21,8 @@ #include #include #include +#include +#include "cmd/package_parser.h" #include "singleton.h" #include "restool_errors.h" @@ -28,73 +30,30 @@ namespace OHOS { namespace Global { namespace Restool { -class ICmdParser { +class CmdParserBase { public: - virtual uint32_t Parse(int argc, char *argv[]) = 0; + CmdParserBase(const std::string &name); + virtual ~CmdParserBase() = default; + virtual uint32_t Parse(int argc, char *argv[], int currentIndex); + virtual uint32_t ParseOption(int argc, char *argv[], int currentIndex); virtual uint32_t ExecCommand() = 0; + virtual void ShowUseage() = 0; +protected: + std::vector> subcommands_; + const std::string name_; + bool showUseage_{true}; }; -template -class CmdParser : public Singleton> { - static_assert(std::is_base_of_v, "Template T must inherit ICmdParser."); +class CmdParser : public CmdParserBase, public Singleton { public: - T &GetCmdParser(); - uint32_t Parse(int argc, char *argv[]); - uint32_t ExecCommand(); - static void ShowUseage(); + CmdParser(); + uint32_t ParseOption(int argc, char *argv[], int currentIndex) override; + uint32_t ExecCommand() override; + void ShowUseage() override; + PackageParser &GetPackageParser(); private: - T cmdParser_; -}; - -template -void CmdParser::ShowUseage() -{ - std::cout << "This is an OHOS Packaging Tool.\n"; - std::cout << "Usage:\n"; - std::cout << TOOL_NAME << " [arguments] Package the OHOS resources.\n"; - std::cout << "[arguments]:\n"; - std::cout << " -i/--inputPath input resource path, can add more.\n"; - std::cout << " -p/--packageName package name.\n"; - std::cout << " -o/--outputPath output path.\n"; - std::cout << " -r/--resHeader resource header file path(like ./ResourceTable.js, ./ResrouceTable.h).\n"; - std::cout << " -f/--forceWrite if output path exists,force delete it.\n"; - std::cout << " -v/--version print tool version.\n"; - std::cout << " -m/--modules module name, can add more, split by ','(like entry1,entry2,...).\n"; - std::cout << " -j/--json config.json path.\n"; - std::cout << " -e/--startId start id mask, e.g 0x01000000,"; - std::cout << " in [0x01000000, 0x06FFFFFF),[0x08000000, 0xFFFFFFFF)\n"; - std::cout << " -x/--append resources folder path\n"; - std::cout << " -z/--combine flag for incremental compilation\n"; - std::cout << " -h/--help Displays this help menu\n"; - std::cout << " -l/--fileList input json file of the option set, e.g resConfig.json."; - std::cout << " For details, see the developer documentation.\n"; - std::cout << " --ids save id_defined.json direcory\n"; - std::cout << " --defined-ids input id_defined.json path\n"; - std::cout << " --dependEntry Build result directory of the specified entry module when the feature"; - std::cout << " module resources are independently built in the FA model.\n"; - std::cout << " --icon-check Enable the PNG image verification function for icons and startwindows.\n"; - std::cout << " --target-config When used with '-i', selective compilation is supported.\n"; - std::cout << " --compressed-config opt-compression.json path.\n"; - std::cout << " dump [config] Dump rsource in hap to json. If with 'config', will only dump limit path.\n"; -} - -template -T &CmdParser::GetCmdParser() -{ - return cmdParser_; -} - -template -uint32_t CmdParser::Parse(int argc, char *argv[]) -{ - return cmdParser_.Parse(argc, argv); -} - -template -uint32_t CmdParser::ExecCommand() -{ - return cmdParser_.ExecCommand(); + PackageParser packageParser_; }; } } diff --git a/include/cmd/dump_parser.h b/include/cmd/dump_parser.h index 5003ed8..549a5cd 100644 --- a/include/cmd/dump_parser.h +++ b/include/cmd/dump_parser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 - 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,23 +16,35 @@ #ifndef OHOS_RESTOOL_DUMP_PARSER_H #define OHOS_RESTOOL_DUMP_PARSER_H -#include "cmd_parser.h" #include #include +#include "cmd_parser.h" namespace OHOS { namespace Global { namespace Restool { -class DumpParser : public ICmdParser { +class DumpParserBase : public virtual CmdParserBase { public: - virtual ~DumpParser() = default; - uint32_t Parse(int argc, char *argv[]) override; - uint32_t ExecCommand() override; + virtual ~DumpParserBase() = default; + uint32_t ParseOption(int argc, char *argv[], int currentIndex) override; + void ShowUseage() override; const std::string &GetInputPath() const; -private: +protected: std::string inputPath_; - std::string type_; +}; + +class DumpParser : public virtual DumpParserBase { +public: + DumpParser(); + uint32_t ExecCommand() override; +}; + +class DumpConfigParser : public virtual DumpParserBase { +public: + DumpConfigParser(); + virtual ~DumpConfigParser() = default; + uint32_t ExecCommand() override; }; } // namespace Restool } // namespace Global diff --git a/include/cmd/package_parser.h b/include/cmd/package_parser.h index 1774d2a..2bec953 100644 --- a/include/cmd/package_parser.h +++ b/include/cmd/package_parser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 - 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,17 +18,20 @@ #include #include -#include "cmd_parser.h" +#include +#include +#include "resource_data.h" +#include "restool_errors.h" namespace OHOS { namespace Global { namespace Restool { -class PackageParser : public ICmdParser { +class PackageParser { public: PackageParser(){}; virtual ~PackageParser() = default; - uint32_t Parse(int argc, char *argv[]) override; - uint32_t ExecCommand() override; + uint32_t Parse(int argc, char *argv[]); + uint32_t ExecCommand(); const std::vector &GetInputs() const; const std::string &GetPackageName() const; const std::string &GetOutput() const; diff --git a/include/resource_dumper.h b/include/resource_dumper.h index 7bf63d7..327a75b 100644 --- a/include/resource_dumper.h +++ b/include/resource_dumper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 - 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -36,7 +36,7 @@ namespace Restool { class ResourceDumper { public: virtual ~ResourceDumper() = default; - virtual uint32_t Dump(const DumpParser &parser); + virtual uint32_t Dump(const DumpParserBase &parser); protected: virtual uint32_t DumpRes(std::string &out) const = 0; void ReadHapInfo(const std::unique_ptr &buffer, size_t len); @@ -69,11 +69,6 @@ private: uint32_t AddItemCommonPropToJson(int32_t resId, const ResourceItem &item, cJSON* json) const; }; -class ResourceDumperFactory { -public: - static std::unique_ptr CreateResourceDumper(const std::string &type); - static const std::set GetSupportDumpType(); -}; } // namespace Restool } // namespace Global } // namespace OHOS diff --git a/include/resource_merge.h b/include/resource_merge.h index e41cef9..964480c 100644 --- a/include/resource_merge.h +++ b/include/resource_merge.h @@ -20,7 +20,7 @@ #include #include "config_parser.h" #include "restool_errors.h" -#include "cmd/package_parser.h" +#include "cmd/cmd_parser.h" namespace OHOS { namespace Global { @@ -29,7 +29,7 @@ class ResourceMerge { public: ResourceMerge(); virtual ~ResourceMerge(); - uint32_t Init(const PackageParser &packageParser = CmdParser::GetInstance().GetCmdParser()); + uint32_t Init(const PackageParser &packageParser = CmdParser::GetInstance().GetPackageParser()); const std::vector &GetInputs() const; private: std::vector inputsOrder_; diff --git a/src/cmd/cmd_parser.cpp b/src/cmd/cmd_parser.cpp new file mode 100644 index 0000000..1652df7 --- /dev/null +++ b/src/cmd/cmd_parser.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "cmd/cmd_parser.h" +#include +#include +#include +#include "cmd/dump_parser.h" +#include "cmd/package_parser.h" +#include "restool_errors.h" + +namespace OHOS { +namespace Global { +namespace Restool { +CmdParserBase::CmdParserBase(const std::string &name) : name_(name) +{} + +uint32_t CmdParserBase::Parse(int argc, char *argv[], int currentIndex) +{ + if (currentIndex < argc) { + for (const auto &subcommand : subcommands_) { + if (subcommand->name_ == argv[currentIndex]) { + return subcommand->Parse(argc, argv, currentIndex + 1); + }; + } + if (std::strcmp(argv[currentIndex], "-h") == 0) { + ShowUseage(); + return RESTOOL_SUCCESS; + } + } + uint32_t errorCode = ParseOption(argc, argv, currentIndex); + if (errorCode != RESTOOL_SUCCESS) { + if (showUseage_) { + ShowUseage(); + } + return errorCode; + } + return ExecCommand(); +} + +uint32_t CmdParserBase::ParseOption(int argc, char *argv[], int currentIndex) +{ + return RESTOOL_SUCCESS; +} + +CmdParser::CmdParser() : CmdParserBase("") +{ + subcommands_.emplace_back(std::make_unique()); +} + +uint32_t CmdParser::ParseOption(int argc, char *argv[], int currentIndex) +{ + if (currentIndex >= argc) { + return RESTOOL_ERROR; + } + return packageParser_.Parse(argc, argv); +} + +uint32_t CmdParser::ExecCommand() +{ + return packageParser_.ExecCommand(); +} + +PackageParser &CmdParser::GetPackageParser() +{ + return packageParser_; +} + +void CmdParser::ShowUseage() +{ + std::cout << "This is an OHOS Packaging Tool.\n"; + std::cout << "Usage:\n"; + std::cout << TOOL_NAME << " [subcommand] files...\n"; + std::cout << TOOL_NAME << " [option1] [option2] [options] files...\n"; + std::cout << "[subcommands]:\n"; + std::cout << " dump Print the contents of the resource in the hap." + "For details about the usage of dump, see '-h'.\n"; + std::cout << "\n"; + std::cout << "[options]:\n"; + std::cout << " -i/--inputPath input resource path, can add more.\n"; + std::cout << " -p/--packageName package name.\n"; + std::cout << " -o/--outputPath output path.\n"; + std::cout << " -r/--resHeader resource header file path(like ./ResourceTable.js, ./ResrouceTable.h).\n"; + std::cout << " -f/--forceWrite if output path exists,force delete it.\n"; + std::cout << " -v/--version print tool version.\n"; + std::cout << " -m/--modules module name, can add more, split by ','(like entry1,entry2,...).\n"; + std::cout << " -j/--json config.json path.\n"; + std::cout << " -e/--startId start id mask, e.g 0x01000000,"; + std::cout << " in [0x01000000, 0x06FFFFFF),[0x08000000, 0xFFFFFFFF)\n"; + std::cout << " -x/--append resources folder path\n"; + std::cout << " -z/--combine flag for incremental compilation\n"; + std::cout << " -h/--help Displays this help menu\n"; + std::cout << " -l/--fileList input json file of the option set, e.g resConfig.json."; + std::cout << " For details, see the developer documentation.\n"; + std::cout << " --ids save id_defined.json direcory\n"; + std::cout << " --defined-ids input id_defined.json path\n"; + std::cout << " --dependEntry Build result directory of the specified entry module when the feature"; + std::cout << " module resources are independently built in the FA model.\n"; + std::cout << " --icon-check Enable the PNG image verification function for icons and startwindows.\n"; + std::cout << " --target-config When used with '-i', selective compilation is supported.\n"; + std::cout << " --compressed-config opt-compression.json path.\n"; +} +} +} +} \ No newline at end of file diff --git a/src/cmd/dump_parser.cpp b/src/cmd/dump_parser.cpp index 57f100b..a2c0a5b 100644 --- a/src/cmd/dump_parser.cpp +++ b/src/cmd/dump_parser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 - 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,6 +14,9 @@ */ #include "cmd/dump_parser.h" +#include +#include +#include "cmd/cmd_parser.h" #include "resource_util.h" #include "resource_dumper.h" @@ -21,21 +24,10 @@ namespace OHOS { namespace Global { namespace Restool { using namespace std; -uint32_t DumpParser::Parse(int argc, char *argv[]) +uint32_t DumpParserBase::ParseOption(int argc, char *argv[], int currentIndex) { - // argv[0] is restool path, argv[1] is 'dump' subcommand. - int currentIndex = 2; if (currentIndex >= argc) { - cerr << "Error: missing input Hap path." << endl; - return RESTOOL_ERROR; - } - const set supportedDumpType = ResourceDumperFactory::GetSupportDumpType(); - if (supportedDumpType.count(argv[currentIndex]) != 0) { - type_ = argv[currentIndex]; - currentIndex++; - } - if (currentIndex >= argc) { - cerr << "Error: missing input Hap path." << endl; + cerr << "Error: missing input path." << endl; return RESTOOL_ERROR; } inputPath_ = ResourceUtil::RealPath(argv[currentIndex]); @@ -46,19 +38,38 @@ uint32_t DumpParser::Parse(int argc, char *argv[]) return RESTOOL_SUCCESS; } -const string& DumpParser::GetInputPath() const +const string& DumpParserBase::GetInputPath() const { return inputPath_; } +DumpParser::DumpParser() : CmdParserBase("dump") +{ + subcommands_.emplace_back(std::make_unique()); +} + uint32_t DumpParser::ExecCommand() { - auto resourceDump = ResourceDumperFactory::CreateResourceDumper(type_); - if (resourceDump) { - return resourceDump->Dump(*this); - } - cerr << "Error: not support dump type '" << type_ << "'" << endl; - return RESTOOL_ERROR; + return CommonDumper().Dump(*this); +} + +void DumpParserBase::ShowUseage() +{ + std::cout << "Usage:\n"; + std::cout << "restool dump [subcommand] [options] file.\n"; + std::cout << "[subcommands]:\n"; + std::cout << " config Print config of the resource in the hap.\n"; + std::cout << "\n"; + std::cout << "[options]:\n"; + std::cout << " -h Print dump subcommand help info.\n"; +} + +DumpConfigParser::DumpConfigParser() : CmdParserBase("config") +{} + +uint32_t DumpConfigParser::ExecCommand() +{ + return ConfigDumper().Dump(*this); } } // namespace Restool } // namespace Global diff --git a/src/cmd/package_parser.cpp b/src/cmd/package_parser.cpp index 09c3d4d..5b41aaf 100644 --- a/src/cmd/package_parser.cpp +++ b/src/cmd/package_parser.cpp @@ -356,7 +356,7 @@ uint32_t PackageParser::AddDependEntry(const string& argValue) uint32_t PackageParser::ShowHelp() const { - auto &parser = CmdParser::GetInstance(); + auto &parser = CmdParser::GetInstance(); parser.ShowUseage(); exit(RESTOOL_SUCCESS); return RESTOOL_SUCCESS; diff --git a/src/id_worker.cpp b/src/id_worker.cpp index a9a62c9..c5147ae 100644 --- a/src/id_worker.cpp +++ b/src/id_worker.cpp @@ -16,6 +16,7 @@ #include "id_worker.h" #include #include +#include "cmd/cmd_parser.h" namespace OHOS { namespace Global { @@ -24,8 +25,8 @@ using namespace std; uint32_t IdWorker::Init(ResourceIdCluster &type, int64_t startId) { type_ = type; - CmdParser &parser = CmdParser::GetInstance(); - PackageParser &packageParser = parser.GetCmdParser(); + CmdParser &parser = CmdParser::GetInstance(); + PackageParser &packageParser = parser.GetPackageParser(); IdDefinedParser idDefinedParser = IdDefinedParser(packageParser, type_); if (idDefinedParser.Init() != RESTOOL_SUCCESS) { return RESTOOL_ERROR; diff --git a/src/resource_dumper.cpp b/src/resource_dumper.cpp index bf1d08c..7652bd2 100644 --- a/src/resource_dumper.cpp +++ b/src/resource_dumper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 - 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -39,7 +39,7 @@ static std::map()>> d {"config", std::make_unique} }; -uint32_t ResourceDumper::Dump(const DumpParser &packageParser) +uint32_t ResourceDumper::Dump(const DumpParserBase &packageParser) { inputPath_ = packageParser.GetInputPath(); if (LoadHap() != RESTOOL_SUCCESS) { @@ -64,6 +64,8 @@ uint32_t ResourceDumper::LoadHap() size_t len; if (ReadFileFromZip(zipFile, "module.json", buffer, len) == RESTOOL_SUCCESS) { ReadHapInfo(buffer, len); + } else if (ReadFileFromZip(zipFile, "config.json", buffer, len) == RESTOOL_SUCCESS) { + ReadHapInfo(buffer, len); } if (ReadFileFromZip(zipFile, "resources.index", buffer, len) != RESTOOL_SUCCESS) { unzClose(zipFile); @@ -80,12 +82,12 @@ uint32_t ResourceDumper::LoadHap() void ResourceDumper::ReadHapInfo(const std::unique_ptr &buffer, size_t len) { - cJSON *module = cJSON_Parse(buffer.get()); - if (!module) { + cJSON *config = cJSON_Parse(buffer.get()); + if (!config) { return; } - cJSON *appConfig = cJSON_GetObjectItemCaseSensitive(module, "app"); - cJSON *moduleConfig = cJSON_GetObjectItemCaseSensitive(module, "module"); + cJSON *appConfig = cJSON_GetObjectItemCaseSensitive(config, "app"); + cJSON *moduleConfig = cJSON_GetObjectItemCaseSensitive(config, "module"); if (appConfig) { cJSON *bundleName = cJSON_GetObjectItemCaseSensitive(appConfig, "bundleName"); if (cJSON_IsString(bundleName) && bundleName->valuestring) { @@ -98,7 +100,7 @@ void ResourceDumper::ReadHapInfo(const std::unique_ptr &buffer, size_t l moduleName_ = moduleName->valuestring; } } - cJSON_Delete(module); + cJSON_Delete(config); } uint32_t ResourceDumper::ReadFileFromZip( @@ -385,24 +387,6 @@ uint32_t ConfigDumper::DumpRes(std::string &out) const rawStr = nullptr; return RESTOOL_SUCCESS; } - -std::unique_ptr ResourceDumperFactory::CreateResourceDumper(const std::string &type) -{ - auto it = dumpMap_.find(type); - if (it != dumpMap_.end()) { - return it->second(); - } - return std::make_unique(); -} - -const std::set ResourceDumperFactory::GetSupportDumpType() -{ - std::set dumpType; - for (auto &it : dumpMap_) { - dumpType.insert(it.first); - } - return dumpType; -} } } } \ No newline at end of file diff --git a/src/resource_table.cpp b/src/resource_table.cpp index 7a555cf..eb363af 100644 --- a/src/resource_table.cpp +++ b/src/resource_table.cpp @@ -16,7 +16,7 @@ #include "resource_table.h" #include #include -#include "cmd/package_parser.h" +#include "cmd/cmd_parser.h" #include "file_entry.h" #include "file_manager.h" #include "resource_util.h" @@ -28,8 +28,8 @@ namespace Restool { using namespace std; ResourceTable::ResourceTable() { - auto &parser = CmdParser::GetInstance(); - auto &packageParser = parser.GetCmdParser(); + auto &parser = CmdParser::GetInstance(); + auto &packageParser = parser.GetPackageParser(); if (!packageParser.GetIdDefinedOutput().empty()) { idDefinedPath_ = FileEntry::FilePath(packageParser.GetIdDefinedOutput()).Append(ID_DEFINED_FILE).GetPath(); } diff --git a/src/restool.cpp b/src/restool.cpp index 1dd3fea..bbc7f2c 100644 --- a/src/restool.cpp +++ b/src/restool.cpp @@ -13,40 +13,23 @@ * limitations under the License. */ -#include -#include "cmd/package_parser.h" -#include "cmd/dump_parser.h" -#include "resource_pack.h" -#include "compression_parser.h" +#include "cmd/cmd_parser.h" +#ifdef _WIN32 +#include +#endif using namespace std; using namespace OHOS::Global::Restool; -constexpr int PARAM_MIN_NUM = 2; - int main(int argc, char *argv[]) { +#ifdef _WIN32 + SetConsoleOutputCP(CP_UTF8); +#endif if (argv == nullptr) { cerr << "Error: argv null" << endl; return RESTOOL_ERROR; } - if (argc < PARAM_MIN_NUM) { - cerr << "Error: At least 1 parameters are required, but no parameter is passed in." << endl; - return RESTOOL_ERROR; - } - if (strcmp(argv[1], "dump") == 0) { - auto &dumpParser = CmdParser::GetInstance(); - if (dumpParser.Parse(argc, argv) != RESTOOL_SUCCESS) { - dumpParser.ShowUseage(); - return RESTOOL_ERROR; - } - return dumpParser.ExecCommand(); - } - auto &packParser = CmdParser::GetInstance(); - if (packParser.Parse(argc, argv) != RESTOOL_SUCCESS) { - packParser.ShowUseage(); - return RESTOOL_ERROR; - } - - return packParser.ExecCommand(); + auto &parser = CmdParser::GetInstance(); + return parser.Parse(argc, argv, 1); } diff --git a/src/select_compile_parse.cpp b/src/select_compile_parse.cpp index 5ce5588..f726d2d 100644 --- a/src/select_compile_parse.cpp +++ b/src/select_compile_parse.cpp @@ -16,7 +16,7 @@ #include "select_compile_parse.h" #include #include "key_parser.h" -#include "cmd/package_parser.h" +#include "cmd/cmd_parser.h" #include "resource_util.h" namespace OHOS { @@ -65,7 +65,7 @@ bool SelectCompileParse::IsSelectCompile(vector &keyParams) if (keyParams.empty()) { return true; } - auto &cmdParser = CmdParser::GetInstance().GetCmdParser(); + auto &cmdParser = CmdParser::GetInstance().GetPackageParser(); bool isTtargetConfig = cmdParser.IsTargetConfig(); if (!isTtargetConfig) { return true;