18 #include "cetlib/container_algorithms.h" 19 #include "cetlib/filepath_maker.h" 20 #include "cetlib/includer.h" 21 #include "cetlib/ostream_handle.h" 22 #include "cetlib/parsed_program_options.h" 23 #include "cetlib_except/exception.h" 32 std::string
const fhicl_env_var{
"FHICL_FILE_PATH"};
35 std::string
const help{
"Help"};
36 std::string
const processing{
"Processing"};
39 using strings = std::vector<string>;
42 string error_filename;
43 string output_filename;
44 strings input_filenames;
45 std::unique_ptr<cet::filepath_maker> policy;
49 Options process_arguments(
int argc,
char** argv);
51 int do_including(std::string
const& starting_filename,
52 cet::filepath_maker& lookup_policy,
60 main(
int argc,
char** argv)
64 opts = process_arguments(argc, argv);
67 if (e.category() == help)
69 if (e.category() == processing)
74 auto out = cet::select_stream(opts.output_filename, std::cout);
75 auto err = cet::select_stream(opts.error_filename, std::cerr);
78 for (std::string
const& filename : opts.input_filenames)
79 nfailures += do_including(filename, *opts.policy, out, err);
89 process_arguments(
int argc,
char** argv)
92 namespace bpo = boost::program_options;
96 bpo::options_description desc(
"fhicl-expand <options> [files]\nOptions");
100 (
"help,h",
"produce help message")
101 (
"inputs,i", bpo::value<strings>(&opts.input_filenames),
"input files")
102 (
"output,o", bpo::value<string>(&opts.output_filename),
"output file")
103 (
"error,e", bpo::value<string>(&opts.error_filename),
"error file")
105 bpo::value<string>()->default_value(
"permissive"),
"see --supported-policies")
107 bpo::value<string>(&opts.lookup_path)->default_value(fhicl_env_var),
108 "path or environment variable to be used by lookup-policy")
109 (
"supported-policies",
"list the supported file lookup policies");
112 bpo::positional_options_description pd;
113 pd.add(
"inputs", -1);
115 auto const vm = cet::parsed_program_options(argc, argv, desc, pd);
119 if (vm.count(
"help")) {
120 std::cout << desc <<
"\n";
124 cet::lookup_policy_selector
const supported_policies{};
125 if (vm.count(
"supported-policies")) {
126 std::cout << supported_policies.help_message();
130 if (vm.count(
"lookup-policy") > 0) {
131 opts.policy = supported_policies.select(
132 vm[
"lookup-policy"].as<std::string>(), opts.lookup_path);
135 if (opts.input_filenames.empty())
136 opts.input_filenames.push_back(
"-");
142 do_including(std::string
const& starting_filename,
143 cet::filepath_maker& lookup_policy,
147 cet::includer inc{starting_filename, lookup_policy};
148 cet::copy_all(inc, std::ostream_iterator<char>{to});
152 err <<
"Error for file: " << starting_filename <<
'\n' << e.what() <<
'\n';
int main(int argc, char **argv)
cet::coded_exception< error, detail::translate > exception