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 EDM_TOOLS_EDM_INCLUDE_EDM_COMMAND_H 17 #define EDM_TOOLS_EDM_INCLUDE_EDM_COMMAND_H 18 19 #include "shell_command.h" 20 #include "enterprise_device_mgr_proxy.h" 21 22 namespace OHOS { 23 namespace EDM { 24 namespace { 25 const std::string TOOL_NAME = "edm"; 26 27 const std::string HELP_MSG = "usage: edm <command> [<options>]\n" 28 "These are common edm commands list:\n" 29 " help list available commands\n" 30 " enable-admin enable a admin with options\n" 31 " disable-admin disable a admin with options\n"; 32 } // namespace 33 34 const std::string HELP_MSG_ENABLE_ADMIN = "usage: edm enable-admin <options>\n" 35 "eg:edm enable-admin -n <bundle-name> -a <ability-name>\n" 36 "options list:\n" 37 " -h, --help list available commands\n" 38 " -n, --bundle-name <bundle-name> enable an admin with bundle name\n" 39 " -a, --ability-name <ability-name> enable an admin with ability name\n"; 40 41 const std::string HELP_MSG_DISABLE_ADMIN = "usage: edm disable-admin <options>\n" 42 "eg:edm disable-admin -n <bundle-name>\n" 43 "options list:\n" 44 " -h, --help list available commands\n" 45 " -n, --bundle-name <bundle-name> disable an admin with bundle name\n"; 46 47 class EdmCommand : public ShellCommand { 48 public: 49 EdmCommand(int argc, char *argv[]); 50 ~EdmCommand() override = default; 51 52 private: 53 ErrCode CreateCommandMap() override; 54 ErrCode CreateMessageMap() override; 55 ErrCode Init() override; 56 ErrCode RunAsHelpCommand(); 57 ErrCode RunAsEnableCommand(); 58 ErrCode RunAsDisableAdminCommand(); 59 ErrCode ParseEnableAdminCommandOption(std::string &bundleName, std::string &abilityName); 60 ErrCode RunAsEnableCommandMissingOptionArgument(); 61 ErrCode RunAsEnableCommandParseOptionArgument(int option, std::string &bundleName, std::string &abilityName); 62 ErrCode ReportMessage(int32_t code, bool isEnable); 63 64 std::shared_ptr<EnterpriseDeviceMgrProxy> enterpriseDeviceMgrProxy_; 65 }; 66 } // namespace EDM 67 } // namespace OHOS 68 69 #endif // EDM_TOOLS_EDM_INCLUDE_EDM_COMMAND_H 70