blob: 19d0395fa543b70bdbeacdc8a38a88599695e393 [file] [log] [blame]
Lei YU0bf1b782019-08-29 16:02:30 +08001/**
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 YU0bf1b782019-08-29 16:02:30 +080016#include "version.hpp"
17
Lei YU093b5912019-10-22 15:28:51 +080018#include <CLI/CLI.hpp>
Lei YU0bf1b782019-08-29 16:02:30 +080019#include <phosphor-logging/log.hpp>
20
Lei YU0bf1b782019-08-29 16:02:30 +080021using namespace phosphor::logging;
22
23int main(int argc, char** argv)
24{
Lei YU093b5912019-10-22 15:28:51 +080025
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 YU0bf1b782019-08-29 16:02:30 +080043 {
Lei YU093b5912019-10-22 15:28:51 +080044 ret = version::getVersion(psuPath);
45 }
46 if (!versions.empty())
47 {
48 ret = version::getLatest(versions);
Lei YU0bf1b782019-08-29 16:02:30 +080049 }
50
Lei YU093b5912019-10-22 15:28:51 +080051 printf("%s", ret.c_str());
52 if (!rawOutput)
53 {
54 printf("\n");
55 }
56 return ret.empty() ? 1 : 0;
Lei YU0bf1b782019-08-29 16:02:30 +080057}