1 /** 2 * Copyright © 2020 IBM Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "utility.hpp" 18 19 #include <CLI/CLI.hpp> 20 21 #include <algorithm> 22 #include <exception> 23 #include <iostream> 24 #include <string> 25 26 using namespace phosphor::power::regulators::control; 27 28 int main(int argc, char* argv[]) 29 { 30 auto rc = 0; 31 32 try 33 { 34 bool monitorEnable = false; 35 bool monitorDisable = false; 36 37 CLI::App app{"Regulators control app for OpenBMC phosphor-regulators"}; 38 39 // Add dbus methods group 40 auto methods = app.add_option_group("Methods"); 41 // Configure method 42 CLI::App* config = 43 methods->add_subcommand("config", "Configure regulators"); 44 config->set_help_flag("-h,--help", "Configure regulators method help"); 45 // Monitor method 46 CLI::App* monitor = 47 methods->add_subcommand("monitor", "Monitor regulators"); 48 monitor->set_help_flag("-h,--help", "Monitor regulators method help"); 49 monitor->add_flag("-e,--enable", monitorEnable, 50 "Enable regulator monitoring"); 51 monitor->add_flag("-d,--disable", monitorDisable, 52 "Disable regulator monitoring"); 53 // Monitor subcommand requires only 1 option be provided 54 monitor->require_option(1); 55 // Methods group requires only 1 subcommand to be given 56 methods->require_subcommand(1); 57 58 CLI11_PARSE(app, argc, argv); 59 60 if (app.got_subcommand("config")) 61 { 62 callMethod("Configure"); 63 } 64 else if (app.got_subcommand("monitor")) 65 { 66 callMethod("Monitor", monitorEnable); 67 } 68 } 69 catch (const std::exception& e) 70 { 71 rc = 1; 72 std::cerr << e.what() << std::endl; 73 } 74 75 return rc; 76 } 77