1 /* 2 * Copyright (c) 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 #ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_SHELLCOMMAND_H 17 #define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_SHELLCOMMAND_H 18 19 #include <map> 20 #include <string> 21 #include <functional> 22 #include <vector> 23 24 #include "packager.h" 25 26 namespace OHOS { 27 namespace AppPackingTool { 28 namespace { 29 const int OFFSET_REQUIRED_ARGUMENT = 2; 30 const std::string HELP_MSG_NO_OPTION = "error: you must specify an option at least."; 31 const std::string STRING_CODE = "code:"; 32 const std::string TOOL_NAME = "apt"; 33 34 const std::string HELP_MSG = "usage: apt <command> <options>\n" 35 "These are common apt commands list:\n" 36 " help list available commands\n" 37 " pack pack a bundle with options\n"; 38 39 } // namespace 40 41 class ShellCommand { 42 public: 43 ShellCommand(int argc, char *argv[], std::string name); 44 virtual ~ShellCommand(); 45 46 int ParseParam(); 47 int OnCommand(); 48 std::string ExecCommand(); 49 int CreateCommandMap(); 50 51 protected: 52 static constexpr int MIN_ARGUMENT_NUMBER = 2; 53 54 int argc_; 55 char **argv_; 56 57 std::string cmd_; 58 std::string name_; 59 std::map<std::string, std::function<int()>> commandMap_; 60 std::map<std::string, std::string> parameterMap_; 61 std::string resultReceiver_ = ""; 62 63 int RunAsHelpCommand(); 64 int RunAsPackCommand(); 65 int RunAsUnpackCommand(); 66 67 private: 68 std::unique_ptr<Packager> getPackager(); 69 }; 70 71 } // namespace AppExecFwk 72 } // namespace OHOS 73 74 #endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_SHELLCOMMAND_H