13 #include <boost/program_options.hpp> 14 #include <boost/algorithm/string.hpp> 15 #include <boost/property_tree/ptree.hpp> 23 namespace po = boost::program_options;
40 po::options_description
desc(
"Options");
42 (
"help,h",
"wire-cell [options] [arguments]")
43 (
"logsink,l",
po::value< vector<string> >(),
"log sink, filename or 'stdout' or 'stderr', if added ':level' then set a log level for the sink")
44 (
"loglevel,L",
po::value< vector<string> >(),
"set lowest log level for a log in form 'name:level' or just 'level' for all (level one of critical,error,warn,info,debug,trace)")
45 (
"app,a",
po::value< vector<string> >(),
"application component to invoke")
46 (
"config,c",
po::value< vector<string> >(),
"provide a configuration file")
47 (
"plugin,p",
po::value< vector<string> >(),
"specify a plugin as name[:lib]")
49 (
"ext-str,V",
po::value< vector<string> >(),
"specify a Jsonnet external variable=value")
50 (
"ext-code,C",
po::value< vector<string> >(),
"specify a Jsonnet external variable=code")
51 (
"path,P",
po::value< vector<string> >(),
"add to JSON/Jsonnet search path")
54 po::variables_map
opts;
55 po::store(po::parse_command_line(argc, argv, desc), opts);
58 if (opts.count(
"help")) {
59 std::cout << desc <<
"\n";
63 if (opts.count(
"config")) {
64 for (
auto fname : opts[
"config"].
as< vector<string> >()) {
69 if (opts.count(
"path")) {
70 for (
auto path : opts[
"path"].
as< vector<string> >()) {
76 if (opts.count(
"ext-str")) {
77 for (
auto vev : opts[
"ext-str"].
as< vector<string> >()) {
83 if (opts.count(
"ext-code")) {
84 for (
auto vev : opts[
"ext-code"].
as< vector<string> >()) {
95 if (opts.count(
"plugin")) {
96 for (
auto plugin : opts[
"plugin"].
as< vector<string> >()) {
100 if (opts.count(
"app")) {
101 for (
auto app : opts[
"app"].
as< vector<string> >()) {
105 if (opts.count(
"logsink")) {
106 for (
auto ls : opts[
"logsink"].
as< vector<string> >()) {
108 if (ll.size() == 1) {
111 if (ll.size() == 2) {
117 if (opts.count(
"loglevel")) {
118 for (
auto ll : opts[
"loglevel"].
as< vector<string> >()) {
120 if (lal.size() == 2) {
149 if (log ==
"stdout") {
153 if (log ==
"stderr") {
187 l->info(
"loading config file {} ...",
filename);
198 if (! main_cfg.isNull()) {
199 for (
auto plugin :
get< vector<string> >(main_cfg,
"data.plugins")) {
200 l->info(
"config requests plugin: \"{}\"", plugin);
203 for (
auto app :
get< vector<string> >(main_cfg,
"data.apps")) {
204 l->info(
"config requests app: \"{}\"", app);
215 l->info(
"adding plugin: \"{}\"", plugin);
217 l->info(
"\t from library \"{}\"", lname);
219 pm.
add(pname, lname);
232 if (
c[
"type"].isNull()) {
233 l->critical(
"all configuration must have a type attribute, got: {}",
c);
236 string type = get<string>(
c,
"type");
237 string name = get<string>(
c,
"name");
238 l->info(
"constructing component: \"{}\":\"{}\"", type, name);
239 auto iface = Factory::lookup<Interface>(
type,
name);
242 l->info(
"constructing app: \"{}\"",
c);
243 Factory::lookup_tn<IApplication>(
c);
249 string type = get<string>(
c,
"type");
250 string name = get<string>(
c,
"name");
251 l->info(
"configuring component: \"{}\":\"{}\"", type, name);
252 auto cfgobj = Factory::find_maybe<IConfigurable>(
type,
name);
260 cfg =
update(cfg, c[
"data"]);
261 cfgobj->configure(cfg);
268 vector<IApplication::pointer> app_objs;
269 for (
auto component :
m_apps) {
272 auto a = Factory::find<IApplication>(
type,
name);
273 app_objs.push_back(
a);
275 l->debug(
"executing {} apps:", m_apps.size());
276 for (
size_t ind=0; ind < m_apps.size(); ++ind) {
277 auto aobj = app_objs[ind];
278 l->debug(
"executing app: \"{}\"", m_apps[ind]);
std::vector< std::string > m_cfgfiles
void add_code(const std::string &name, const std::string &value)
Configuration update(Configuration &a, Configuration &b)
Merge dictionary b into a, return a.
void add_stdout(bool color=true, std::string level="")
int cmdline(int argc, char *argv[])
boost::error_info< struct tag_errmsg, std::string > errmsg
void add_logsink(const std::string &log, const std::string &level="")
Add a log sink, reserved names 'stdout' and 'stderr' or a filename.
std::pair< std::string, std::string > parse_pair(const std::string &in, const std::string &delim=":")
std::vector< std::string > m_plugins
void set_level(std::string level, std::string which="")
void set_pattern(std::string pattern, std::string which="")
Persist::externalvars_t m_extcode
static PluginManager & instance()
void extend(Configuration more)
Extend current list of configuration objects with more.
Configuration all() const
Return top-level, aggregate configuration.
void add_config(const std::string &filename)
std::vector< std::string > m_apps
void add_path(const std::string &dirname)
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
void add_stderr(bool color=true, std::string level="")
void add_var(const std::string &name, const std::string &value)
logptr_t logger(std::string name)
Thrown when a wrong value has been encountered.
std::vector< std::string > m_load_path
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
void log(source_loc source, level::level_enum lvl, const char *fmt, const Args &...args)
void add_app(const std::string &tn)
void operator()()
Run any and all application components once.
int index(const std::string &type, const std::string &name="") const
void add_file(std::string filename, std::string level="")
Json::Value load(const std::string &filename)
std::string type(const T &t)
const GenericPointer< typename T::ValueType > T2 value
Json::Value Configuration
void add_plugin(const std::string &libname)
std::vector< std::string > split(const std::string &in, const std::string &delim=":")
Plugin * add(const std::string &plugin_name, const std::string &libname="")
Add a plugin. If libname is not given, try to derive it.
Persist::externalvars_t m_extvars
void set_loglevel(const std::string &log, const std::string &level="")
Configuration pop(int ind)
Remove configuration at given index and return it.