comparison irccd-test/main.cpp @ 746:fe3d80412701

Irccd: load config in irccd-test
author David Demelier <markand@malikania.fr>
date Fri, 03 Aug 2018 12:15:00 +0200
parents e08bfc940c54
children c216d148558d
comparison
equal deleted inserted replaced
745:903415e8ee2e 746:fe3d80412701
591 plugin = daemon->plugins().get("test"); 591 plugin = daemon->plugins().get("test");
592 } 592 }
593 593
594 // }}} 594 // }}}
595 595
596 // {{{ load_config
597
598 auto load_config(const option::result& result) -> config
599 {
600 auto it = result.find("-c");
601
602 if (it != result.end() || (it = result.find("--config")) != result.end())
603 return config(it->second);
604
605 auto cfg = config::search("irccd.conf");
606
607 return *cfg;
608 }
609
610 // }}}
611
596 // {{{ load_options 612 // {{{ load_options
597 613
598 void load_options(int& argc, char**& argv) 614 void load_options(int& argc, char**& argv)
599 { 615 {
600 const option::options def{ 616 static const option::options def{
601 { "-c", true }, 617 { "-c", true },
602 { "--config", true } 618 { "--config", true }
603 }; 619 };
604 620
605 auto result = option::read(argc, argv, def); 621 try {
606 auto it = result.find("-c"); 622 daemon->set_config(load_config(option::read(argc, argv, def)));
607 623 } catch (const std::exception& ex) {
608 if (it == result.end()) 624 throw std::runtime_error(str(format("%1%") % ex.what()));
609 it = result.find("--config");
610 if (it != result.end()) {
611 try {
612 daemon->set_config(it->second);
613 } catch (const std::exception& ex) {
614 throw std::runtime_error(str(format("%1%: %2%") % it->second % ex.what()));
615 }
616 } 625 }
617 } 626 }
618 627
619 // }}} 628 // }}}
620 629