# HG changeset patch # User David Demelier # Date 1466537008 -7200 # Node ID b9c3a58d193bf502ba62f4bcc69b8a1cf57c2acd # Parent 6635b9187d714c9fbc02d83b0072f6e9dc6e7133 Irccd: fix usage of option parser diff -r 6635b9187d71 -r b9c3a58d193b irccd/main.cpp --- a/irccd/main.cpp Tue Jun 21 20:52:17 2016 +0200 +++ b/irccd/main.cpp Tue Jun 21 21:23:28 2016 +0200 @@ -90,13 +90,13 @@ ++ argv; } -parser::Result parse(int &argc, char **&argv) +option::Result parse(int &argc, char **&argv) { // Parse command line options. - parser::Result result; + option::Result result; try { - parser::Options options{ + option::Options options{ { "-c", true }, { "--config", true }, { "-f", false }, @@ -109,7 +109,7 @@ { "--version", false } }; - result = parser::read(argc, argv, options); + result = option::read(argc, argv, options); for (const auto &pair : result) { if (pair.first == "--help") @@ -130,7 +130,7 @@ return result; } -Config open(const parser::Result &result) +Config open(const option::Result &result) { auto it = result.find("-c"); @@ -195,7 +195,7 @@ } } -void loadForeground(bool foreground, const parser::Result &options) +void loadForeground(bool foreground, const option::Result &options) { try { #if defined(HAVE_DAEMON) @@ -210,7 +210,7 @@ } } -void load(const Config &config, const parser::Result &options) +void load(const Config &config, const option::Result &options) { /* * Order matters, please be careful when changing this. @@ -253,7 +253,7 @@ { init(argc, argv); - parser::Result options = parse(argc, argv); + option::Result options = parse(argc, argv); // Find configuration file. instance = std::make_unique(); diff -r 6635b9187d71 -r b9c3a58d193b lib/irccd/irccdctl.cpp --- a/lib/irccd/irccdctl.cpp Tue Jun 21 20:52:17 2016 +0200 +++ b/lib/irccd/irccdctl.cpp Tue Jun 21 21:23:28 2016 +0200 @@ -43,11 +43,6 @@ using namespace fmt::literals; -using namespace net; -using namespace net::address; -using namespace net::option; -using namespace net::protocol; - using namespace std::placeholders; using namespace std::chrono_literals; using namespace std::string_literals; @@ -158,7 +153,7 @@ throw std::invalid_argument("invalid domain: " + it->value()); } - m_connection = std::make_unique>(Ip::resolve(host, std::to_string(port), domain)); + m_connection = std::make_unique>(net::address::Ip::resolve(host, std::to_string(port), domain)); } void Irccdctl::readConnectUnix(const ini::Section &sc) @@ -169,7 +164,7 @@ if (it == sc.end()) throw std::invalid_argument("missing path parameter"); - m_connection = std::make_unique>(Local{it->value(), false}); + m_connection = std::make_unique>(net::address::Local(it->value(), false)); #else (void)sc; @@ -239,7 +234,7 @@ } } -void Irccdctl::read(const std::string &path, const parser::Result &options) +void Irccdctl::read(const std::string &path, const option::Result &options) { ini::Document doc = ini::readFile(path); ini::Document::const_iterator it = doc.find("connect"); @@ -258,9 +253,9 @@ * ------------------------------------------------------------------ */ -void Irccdctl::parseConnectIp(const parser::Result &options, bool ipv6) +void Irccdctl::parseConnectIp(const option::Result &options, bool ipv6) { - parser::Result::const_iterator it; + option::Result::const_iterator it; // Host (-h or --host). std::string host; @@ -285,18 +280,18 @@ // Domain int domain = (ipv6) ? AF_INET6 : AF_INET; - m_connection = std::make_unique>(Ip::resolve(host, std::to_string(port), domain, SOCK_STREAM)); + m_connection = std::make_unique>(net::address::Ip::resolve(host, std::to_string(port), domain, SOCK_STREAM)); } -void Irccdctl::parseConnectUnix(const parser::Result &options) +void Irccdctl::parseConnectUnix(const option::Result &options) { #if !defined(IRCCD_SYSTEM_WINDOWS) - parser::Result::const_iterator it; + option::Result::const_iterator it; if ((it = options.find("-P")) == options.end() && (it = options.find("--path")) == options.end()) throw std::invalid_argument("missing path parameter (-P or --path)"); - m_connection = std::make_unique>(Local{it->second, false}); + m_connection = std::make_unique>(net::address::Local(it->second, false)); #else (void)options; @@ -304,7 +299,7 @@ #endif } -void Irccdctl::parseConnect(const parser::Result &options) +void Irccdctl::parseConnect(const option::Result &options) { assert(options.count("-t") > 0 || options.count("--type") > 0); @@ -320,10 +315,10 @@ throw std::invalid_argument("invalid type given: " + it->second); } -parser::Result Irccdctl::parse(int &argc, char **&argv) const +option::Result Irccdctl::parse(int &argc, char **&argv) const { // 1. Parse command line options. - parser::Options def{ + option::Options def{ { "-c", true }, { "--config", true }, { "-h", true }, @@ -339,10 +334,10 @@ { "--verbose", false } }; - parser::Result result; + option::Result result; try { - result = parser::read(argc, argv, def); + result = option::read(argc, argv, def); if (result.count("--help") != 0) { usage(); @@ -362,7 +357,7 @@ void Irccdctl::exec(const Command &cmd, std::vector args) { // 1. Build options from command line arguments. - parser::Options def; + option::Options def; for (const auto &opt : cmd.options()) { // parser::read needs '-' and '--' so add them. @@ -375,7 +370,7 @@ // 2. Parse them, remove them from args (in parser::read) and build the map with id. CommandRequest::Options requestOptions; - for (const auto &pair : parser::read(args, def)) { + for (const auto &pair : option::read(args, def)) { auto options = cmd.options(); auto it = std::find_if(options.begin(), options.end(), [&] (const auto &opt) { return ("-"s + opt.simpleKey()) == pair.first || ("--"s + opt.longKey()) == pair.first; @@ -491,7 +486,7 @@ void Irccdctl::run(int argc, char **argv) { // 1. Read command line arguments. - parser::Result result = parse(argc, argv); + option::Result result = parse(argc, argv); /* * 2. Open optional config by command line or by searching it diff -r 6635b9187d71 -r b9c3a58d193b lib/irccd/irccdctl.hpp --- a/lib/irccd/irccdctl.hpp Tue Jun 21 20:52:17 2016 +0200 +++ b/lib/irccd/irccdctl.hpp Tue Jun 21 21:23:28 2016 +0200 @@ -71,12 +71,12 @@ void readConnect(const ini::Section &sc); void readGeneral(const ini::Section &sc); void readAliases(const ini::Section &sc); - void read(const std::string &path, const parser::Result &options); + void read(const std::string &path, const option::Result &options); - void parseConnectIp(const parser::Result &options, bool ipv6); - void parseConnectUnix(const parser::Result &options); - void parseConnect(const parser::Result &options); - parser::Result parse(int &argc, char **&argv) const; + void parseConnectIp(const option::Result &options, bool ipv6); + void parseConnectUnix(const option::Result &options); + void parseConnect(const option::Result &options); + option::Result parse(int &argc, char **&argv) const; void connect(); diff -r 6635b9187d71 -r b9c3a58d193b lib/irccd/options.cpp --- a/lib/irccd/options.cpp Tue Jun 21 20:52:17 2016 +0200 +++ b/lib/irccd/options.cpp Tue Jun 21 21:23:28 2016 +0200 @@ -20,6 +20,8 @@ #include "options.hpp" +namespace irccd { + namespace option { namespace { @@ -177,3 +179,5 @@ } } // !option + +} // !irccd