]> granicus.if.org Git - icinga2/blob - lib/cli/variablelistcommand.cpp
add some object locking to the Dump method (which could theoreticylly suffer from...
[icinga2] / lib / cli / variablelistcommand.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "cli/variablelistcommand.hpp"
4 #include "cli/variableutility.hpp"
5 #include "base/logger.hpp"
6 #include "base/application.hpp"
7 #include "base/convert.hpp"
8 #include "base/configobject.hpp"
9 #include "base/debug.hpp"
10 #include "base/objectlock.hpp"
11 #include "base/console.hpp"
12 #include <boost/algorithm/string/join.hpp>
13 #include <boost/algorithm/string/replace.hpp>
14 #include <fstream>
15 #include <iostream>
16
17 using namespace icinga;
18 namespace po = boost::program_options;
19
20 REGISTER_CLICOMMAND("variable/list", VariableListCommand);
21
22 String VariableListCommand::GetDescription() const
23 {
24         return "Lists all Icinga 2 variables.";
25 }
26
27 String VariableListCommand::GetShortDescription() const
28 {
29         return "lists all variables";
30 }
31
32 /**
33  * The entry point for the "variable list" CLI command.
34  *
35  * @returns An exit status.
36  */
37 int VariableListCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
38 {
39         String varsfile = Configuration::VarsPath;
40
41         if (!Utility::PathExists(varsfile)) {
42                 Log(LogCritical, "cli")
43                         << "Cannot open variables file '" << varsfile << "'.";
44                 Log(LogCritical, "cli", "Run 'icinga2 daemon -C' to validate config and generate the cache file.");
45                 return 1;
46         }
47
48         VariableUtility::PrintVariables(std::cout);
49
50         return 0;
51 }
52