Brandon Wyman | 2ad76bd | 2019-08-26 17:15:04 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 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 | #include <CLI/CLI.hpp> |
Brandon Wyman | 57939e8 | 2019-08-26 17:53:57 -0500 | [diff] [blame^] | 17 | #include <phosphor-logging/log.hpp> |
| 18 | |
| 19 | #include <filesystem> |
Brandon Wyman | 2ad76bd | 2019-08-26 17:15:04 -0500 | [diff] [blame] | 20 | |
| 21 | int main(int argc, char* argv[]) |
| 22 | { |
Brandon Wyman | 57939e8 | 2019-08-26 17:53:57 -0500 | [diff] [blame^] | 23 | using namespace phosphor::logging; |
Brandon Wyman | 2ad76bd | 2019-08-26 17:15:04 -0500 | [diff] [blame] | 24 | |
| 25 | CLI::App app{"OpenBMC Power Supply Unit Monitor"}; |
Brandon Wyman | 57939e8 | 2019-08-26 17:53:57 -0500 | [diff] [blame^] | 26 | |
| 27 | std::string configfile; |
| 28 | app.add_option("-c,--config", configfile, "JSON configuration file path") |
| 29 | ->check(CLI::ExistingFile); |
| 30 | |
Brandon Wyman | 2ad76bd | 2019-08-26 17:15:04 -0500 | [diff] [blame] | 31 | // Read the arguments. |
| 32 | CLI11_PARSE(app, argc, argv); |
Brandon Wyman | 57939e8 | 2019-08-26 17:53:57 -0500 | [diff] [blame^] | 33 | if (configfile.empty()) |
| 34 | { |
| 35 | configfile = "/etc/phosphor-psu-monitor/psu_config.json"; |
| 36 | } |
Brandon Wyman | 2ad76bd | 2019-08-26 17:15:04 -0500 | [diff] [blame] | 37 | |
Brandon Wyman | 57939e8 | 2019-08-26 17:53:57 -0500 | [diff] [blame^] | 38 | if (!std::filesystem::exists(configfile)) |
| 39 | { |
| 40 | log<level::ERR>("Configuration file does not exist", |
| 41 | entry("FILENAME=%s", configfile.c_str())); |
| 42 | return -1; |
| 43 | } |
Brandon Wyman | 2ad76bd | 2019-08-26 17:15:04 -0500 | [diff] [blame] | 44 | |
Brandon Wyman | 57939e8 | 2019-08-26 17:53:57 -0500 | [diff] [blame^] | 45 | return 0; |
Brandon Wyman | 2ad76bd | 2019-08-26 17:15:04 -0500 | [diff] [blame] | 46 | } |