blob: 9f65c8bae0141f56ac974d6755e0754b81e56e6f [file] [log] [blame]
Matthew Barth32707082020-04-13 13:59:04 -05001/**
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>
Shawn McCarney415094c2021-02-15 11:08:19 -060022#include <exception>
Matthew Barth32707082020-04-13 13:59:04 -050023#include <iostream>
24#include <string>
25
26using namespace phosphor::power::regulators::control;
27
28int main(int argc, char* argv[])
29{
30 auto rc = 0;
31
Shawn McCarney415094c2021-02-15 11:08:19 -060032 try
Matthew Barth32707082020-04-13 13:59:04 -050033 {
Shawn McCarney415094c2021-02-15 11:08:19 -060034 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"))
Matthew Barth32707082020-04-13 13:59:04 -050061 {
Shawn McCarney415094c2021-02-15 11:08:19 -060062 callMethod("Configure");
63 }
64 else if (app.got_subcommand("monitor"))
65 {
66 callMethod("Monitor", monitorEnable);
Matthew Barth32707082020-04-13 13:59:04 -050067 }
68 }
Shawn McCarney415094c2021-02-15 11:08:19 -060069 catch (const std::exception& e)
Matthew Barth32707082020-04-13 13:59:04 -050070 {
Shawn McCarney415094c2021-02-15 11:08:19 -060071 rc = 1;
72 std::cerr << e.what() << std::endl;
Matthew Barth32707082020-04-13 13:59:04 -050073 }
74
75 return rc;
76}