Lei YU | 0bf1b78 | 2019-08-29 16:02:30 +0800 | [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 | */ |
Lei YU | 0bf1b78 | 2019-08-29 16:02:30 +0800 | [diff] [blame] | 16 | #include "version.hpp" |
| 17 | |
Lei YU | 093b591 | 2019-10-22 15:28:51 +0800 | [diff] [blame^] | 18 | #include <CLI/CLI.hpp> |
Lei YU | 0bf1b78 | 2019-08-29 16:02:30 +0800 | [diff] [blame] | 19 | #include <phosphor-logging/log.hpp> |
| 20 | |
Lei YU | 0bf1b78 | 2019-08-29 16:02:30 +0800 | [diff] [blame] | 21 | using namespace phosphor::logging; |
| 22 | |
| 23 | int main(int argc, char** argv) |
| 24 | { |
Lei YU | 093b591 | 2019-10-22 15:28:51 +0800 | [diff] [blame^] | 25 | |
| 26 | std::string psuPath; |
| 27 | std::vector<std::string> versions; |
| 28 | bool rawOutput = false; |
| 29 | |
| 30 | CLI::App app{"PSU utils app for OpenBMC"}; |
| 31 | auto action = app.add_option_group("Action"); |
| 32 | action->add_option("-g,--get-version", psuPath, |
| 33 | "Get PSU version from inventory path"); |
| 34 | action->add_option("-c,--compare", versions, |
| 35 | "Compare and get the latest version"); |
| 36 | action->require_option(1); // Only one option is supported |
| 37 | app.add_flag("--raw", rawOutput, "Output raw text without linefeed"); |
| 38 | CLI11_PARSE(app, argc, argv); |
| 39 | |
| 40 | std::string ret; |
| 41 | |
| 42 | if (!psuPath.empty()) |
Lei YU | 0bf1b78 | 2019-08-29 16:02:30 +0800 | [diff] [blame] | 43 | { |
Lei YU | 093b591 | 2019-10-22 15:28:51 +0800 | [diff] [blame^] | 44 | ret = version::getVersion(psuPath); |
| 45 | } |
| 46 | if (!versions.empty()) |
| 47 | { |
| 48 | ret = version::getLatest(versions); |
Lei YU | 0bf1b78 | 2019-08-29 16:02:30 +0800 | [diff] [blame] | 49 | } |
| 50 | |
Lei YU | 093b591 | 2019-10-22 15:28:51 +0800 | [diff] [blame^] | 51 | printf("%s", ret.c_str()); |
| 52 | if (!rawOutput) |
| 53 | { |
| 54 | printf("\n"); |
| 55 | } |
| 56 | return ret.empty() ? 1 : 0; |
Lei YU | 0bf1b78 | 2019-08-29 16:02:30 +0800 | [diff] [blame] | 57 | } |