xref: /freebsd/contrib/kyua/engine/prepare/prepare_all.cpp (revision edb230c4af499203d7a6894b3711fe6574b26040)
1*edb230c4SIgor Ostapenko // Copyright 2024 The Kyua Authors.
2*edb230c4SIgor Ostapenko // All rights reserved.
3*edb230c4SIgor Ostapenko //
4*edb230c4SIgor Ostapenko // Redistribution and use in source and binary forms, with or without
5*edb230c4SIgor Ostapenko // modification, are permitted provided that the following conditions are
6*edb230c4SIgor Ostapenko // met:
7*edb230c4SIgor Ostapenko //
8*edb230c4SIgor Ostapenko // * Redistributions of source code must retain the above copyright
9*edb230c4SIgor Ostapenko //   notice, this list of conditions and the following disclaimer.
10*edb230c4SIgor Ostapenko // * Redistributions in binary form must reproduce the above copyright
11*edb230c4SIgor Ostapenko //   notice, this list of conditions and the following disclaimer in the
12*edb230c4SIgor Ostapenko //   documentation and/or other materials provided with the distribution.
13*edb230c4SIgor Ostapenko // * Neither the name of Google Inc. nor the names of its contributors
14*edb230c4SIgor Ostapenko //   may be used to endorse or promote products derived from this software
15*edb230c4SIgor Ostapenko //   without specific prior written permission.
16*edb230c4SIgor Ostapenko //
17*edb230c4SIgor Ostapenko // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*edb230c4SIgor Ostapenko // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*edb230c4SIgor Ostapenko // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*edb230c4SIgor Ostapenko // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*edb230c4SIgor Ostapenko // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*edb230c4SIgor Ostapenko // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*edb230c4SIgor Ostapenko // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*edb230c4SIgor Ostapenko // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*edb230c4SIgor Ostapenko // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*edb230c4SIgor Ostapenko // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*edb230c4SIgor Ostapenko // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*edb230c4SIgor Ostapenko 
29*edb230c4SIgor Ostapenko #include "engine/prepare/prepare_all.hpp"
30*edb230c4SIgor Ostapenko 
31*edb230c4SIgor Ostapenko static const std::string _name = "all";
32*edb230c4SIgor Ostapenko static const std::string _description = "Run all preparations";
33*edb230c4SIgor Ostapenko 
34*edb230c4SIgor Ostapenko namespace prepare = engine::prepare;
35*edb230c4SIgor Ostapenko 
36*edb230c4SIgor Ostapenko 
37*edb230c4SIgor Ostapenko const std::string&
name() const38*edb230c4SIgor Ostapenko prepare::prepare_all::name() const
39*edb230c4SIgor Ostapenko {
40*edb230c4SIgor Ostapenko     return _name;
41*edb230c4SIgor Ostapenko }
42*edb230c4SIgor Ostapenko 
43*edb230c4SIgor Ostapenko 
44*edb230c4SIgor Ostapenko const std::string&
description() const45*edb230c4SIgor Ostapenko prepare::prepare_all::description() const
46*edb230c4SIgor Ostapenko {
47*edb230c4SIgor Ostapenko     return _description;
48*edb230c4SIgor Ostapenko }
49*edb230c4SIgor Ostapenko 
50*edb230c4SIgor Ostapenko 
51*edb230c4SIgor Ostapenko int
exec(cmdline::ui * ui,const cmdline::parsed_cmdline & cmdline,const config::tree & user_config) const52*edb230c4SIgor Ostapenko prepare::prepare_all::exec(cmdline::ui* ui,
53*edb230c4SIgor Ostapenko                            const cmdline::parsed_cmdline& cmdline,
54*edb230c4SIgor Ostapenko                            const config::tree& user_config) const
55*edb230c4SIgor Ostapenko {
56*edb230c4SIgor Ostapenko     for (auto& handler : prepare::handlers()) {
57*edb230c4SIgor Ostapenko         if (handler->name() == this->name())
58*edb230c4SIgor Ostapenko             continue;
59*edb230c4SIgor Ostapenko 
60*edb230c4SIgor Ostapenko         int error = handler->exec(ui, cmdline, user_config);
61*edb230c4SIgor Ostapenko         if (error != EXIT_SUCCESS)
62*edb230c4SIgor Ostapenko             return error;
63*edb230c4SIgor Ostapenko     }
64*edb230c4SIgor Ostapenko 
65*edb230c4SIgor Ostapenko     return EXIT_SUCCESS;
66*edb230c4SIgor Ostapenko }
67