blob: 10c3ffae2ac668d9d71efcf93affbd62cb2ee3aa [file] [log] [blame]
Matt Spinlerf716f322017-02-28 09:37:38 -06001/**
2 * Copyright © 2017 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 <algorithm>
17#include <functional>
18#include <iostream>
19#include <phosphor-logging/log.hpp>
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060020#include "registration.hpp"
Matt Spinlerf716f322017-02-28 09:37:38 -060021
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060022using namespace openpower::util;
Matt Spinlerf716f322017-02-28 09:37:38 -060023
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060024void usage(char** argv, const ProcedureMap& procedures)
Matt Spinlerf716f322017-02-28 09:37:38 -060025{
26 std::cerr << "Usage: " << argv[0] << " [action]\n";
27 std::cerr << " actions:\n";
28
29 for (const auto& p : procedures)
30 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060031 std::cerr << " " << p.first << "\n";
Matt Spinlerf716f322017-02-28 09:37:38 -060032 }
33}
34
35int main(int argc, char** argv)
36{
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060037 const ProcedureMap& procedures = Registration::getProcedures();
38
Matt Spinlerf716f322017-02-28 09:37:38 -060039 if (argc != 2)
40 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060041 usage(argv, procedures);
Matt Spinlerf716f322017-02-28 09:37:38 -060042 return -1;
43 }
44
45 std::string action{argv[1]};
46
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060047 auto procedure = procedures.find(action);
Matt Spinlerf716f322017-02-28 09:37:38 -060048
49 if (procedure == procedures.end())
50 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060051 usage(argv, procedures);
Matt Spinlerf716f322017-02-28 09:37:38 -060052 return -1;
53 }
54
Matt Spinlerf716f322017-02-28 09:37:38 -060055 try
56 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060057 procedure->second();
Matt Spinlerf716f322017-02-28 09:37:38 -060058 }
59 catch (std::exception& e)
60 {
61 //TODO: commit an actual error that does a callout
62 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
63 return -1;
64 }
65
66 return 0;
67}