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