162b36bd8SMatt Spinler /**
262b36bd8SMatt Spinler  * Copyright © 2017 IBM Corporation
362b36bd8SMatt Spinler  *
462b36bd8SMatt Spinler  * Licensed under the Apache License, Version 2.0 (the "License");
562b36bd8SMatt Spinler  * you may not use this file except in compliance with the License.
662b36bd8SMatt Spinler  * You may obtain a copy of the License at
762b36bd8SMatt Spinler  *
862b36bd8SMatt Spinler  *     http://www.apache.org/licenses/LICENSE-2.0
962b36bd8SMatt Spinler  *
1062b36bd8SMatt Spinler  * Unless required by applicable law or agreed to in writing, software
1162b36bd8SMatt Spinler  * distributed under the License is distributed on an "AS IS" BASIS,
1262b36bd8SMatt Spinler  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1362b36bd8SMatt Spinler  * See the License for the specific language governing permissions and
1462b36bd8SMatt Spinler  * limitations under the License.
1562b36bd8SMatt Spinler  */
1662b36bd8SMatt Spinler 
1762b36bd8SMatt Spinler /**
1862b36bd8SMatt Spinler  * This application will check the ActiveState property
1962b36bd8SMatt Spinler  * on the source unit passed in.  If that state is 'failed',
2062b36bd8SMatt Spinler  * then it will either stop or start the target unit, depending
2162b36bd8SMatt Spinler  * on the command line arguments.
2262b36bd8SMatt Spinler  */
238b633b7eSMatt Spinler #include "monitor.hpp"
2462b36bd8SMatt Spinler 
25*8c243629SBrad Bishop #include <CLI/CLI.hpp>
26*8c243629SBrad Bishop 
27cc6ee9cbSMatt Spinler #include <map>
28*8c243629SBrad Bishop #include <string>
29cc6ee9cbSMatt Spinler 
308b633b7eSMatt Spinler using namespace phosphor::unit::failure;
318b633b7eSMatt Spinler 
32167e2379SEd Tanous static const std::map<std::string, Monitor::Action> actions = {
33167e2379SEd Tanous     {"start", Monitor::Action::start}, {"stop", Monitor::Action::stop}};
3462b36bd8SMatt Spinler 
main(int argc,char ** argv)3562b36bd8SMatt Spinler int main(int argc, char** argv)
3662b36bd8SMatt Spinler {
37*8c243629SBrad Bishop     CLI::App app;
38*8c243629SBrad Bishop     std::string source;
39*8c243629SBrad Bishop     std::string target;
40*8c243629SBrad Bishop     Monitor::Action action{Monitor::Action::start};
4162b36bd8SMatt Spinler 
42*8c243629SBrad Bishop     app.add_option("-s,--source", source, "The source unit to monitor")
43*8c243629SBrad Bishop         ->required();
44*8c243629SBrad Bishop     app.add_option("-t,--target", target, "The target unit to start or stop")
45*8c243629SBrad Bishop         ->required();
46*8c243629SBrad Bishop     app.add_option("-a,--action", action, "Target unit action - start or stop")
47*8c243629SBrad Bishop         ->required()
48*8c243629SBrad Bishop         ->transform(CLI::CheckedTransformer(actions, CLI::ignore_space));
498b633b7eSMatt Spinler 
50*8c243629SBrad Bishop     CLI11_PARSE(app, argc, argv);
51*8c243629SBrad Bishop     Monitor monitor{source, target, action};
528b633b7eSMatt Spinler 
538b633b7eSMatt Spinler     monitor.analyze();
5462b36bd8SMatt Spinler 
5562b36bd8SMatt Spinler     return 0;
5662b36bd8SMatt Spinler }
57