summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-11-12 22:35:27 +0100
committerFlorent Le Coz <louiz@louiz.org>2013-11-12 22:35:27 +0100
commitb60cbda4f93bb83e36b29f5cba975b94b833663d (patch)
tree50596af4066221ad21a16fe864732c46e701e1f0
parent2be4811d14f921f92e7f976b6e3c9ceb5404086b (diff)
downloadbiboumi-b60cbda4f93bb83e36b29f5cba975b94b833663d.tar.gz
biboumi-b60cbda4f93bb83e36b29f5cba975b94b833663d.tar.bz2
biboumi-b60cbda4f93bb83e36b29f5cba975b94b833663d.tar.xz
biboumi-b60cbda4f93bb83e36b29f5cba975b94b833663d.zip
Read the served hostname from the config file
-rw-r--r--src/main.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 80c8436..71c93f9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,26 +5,42 @@
#include <iostream>
#include <memory>
+/**
+ * Provide an helpful message to help the user write a minimal working
+ * configuration file.
+ */
+int config_help(const std::string& missing_option)
+{
+ if (!missing_option.empty())
+ std::cerr << "Error: empty value for option " << missing_option << "." << std::endl;
+ std::cerr <<
+ "Please provide a configuration file filled like this:\n\n"
+ "hostname=irc.example.com\npassword=S3CR3T"
+ << std::endl;
+ return 1;
+}
+
int main(int ac, char** av)
{
if (ac > 1)
Config::filename = av[1];
Config::file_must_exist = true;
+ std::cerr << "Using configuration file: " << Config::filename << std::endl;
std::string password;
try { // The file must exist
password = Config::get("password", "");
}
catch (const std::ios::failure& e) {
- return 1;
+ return config_help("");
}
+ const std::string hostname = Config::get("hostname", "");
if (password.empty())
- {
- std::cerr << "No password provided." << std::endl;
- return 1;
- }
+ return config_help("hostname");
+ if (hostname.empty())
+ return config_help("password");
std::shared_ptr<XmppComponent> xmpp_component =
- std::make_shared<XmppComponent>("irc.abricot", password);
+ std::make_shared<XmppComponent>(hostname, password);
Poller p;
p.add_socket_handler(xmpp_component);