1 /**
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>
20 #include "registration.hpp"
21 
22 using namespace openpower::util;
23 
24 void usage(char** argv, const ProcedureMap& procedures)
25 {
26     std::cerr << "Usage: " << argv[0] << " [action]\n";
27     std::cerr << "   actions:\n";
28 
29     for (const auto& p : procedures)
30     {
31         std::cerr << "     " << p.first << "\n";
32     }
33 }
34 
35 int main(int argc, char** argv)
36 {
37     const ProcedureMap& procedures = Registration::getProcedures();
38 
39     if (argc != 2)
40     {
41         usage(argv, procedures);
42         return -1;
43     }
44 
45     std::string action{argv[1]};
46 
47     auto procedure = procedures.find(action);
48 
49     if (procedure == procedures.end())
50     {
51         usage(argv, procedures);
52         return -1;
53     }
54 
55     try
56     {
57         procedure->second();
58     }
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 }
68