7 #include "cetlib/filepath_maker.h" 8 #include "cetlib/ostream_handle.h" 9 #include "cetlib/parsed_program_options.h" 10 #include "cetlib_except/demangle.h" 20 using namespace fhicl;
27 string const fhicl_env_var{
"FHICL_FILE_PATH"};
30 string const help{
"Help"};
31 string const processing{
"Processing"};
32 string const config{
"Configuration"};
41 string output_filename;
42 string input_filename;
43 std::unique_ptr<cet::filepath_maker> policy;
47 std::variant<Options, Help> process_arguments(
int argc,
char** argv);
53 main(
int argc,
char** argv)
55 auto const opts_or_help = process_arguments(argc, argv);
56 if (std::holds_alternative<Help>(opts_or_help)) {
57 std::cout << std::get<Help>(opts_or_help).msg;
61 auto const& opts = std::get<Options>(opts_or_help);
68 auto os = cet::select_stream(opts.output_filename, std::cout);
70 os <<
"# Produced from '" << argv[0] <<
"' using:\n" 71 <<
"# Input : " << opts.input_filename <<
'\n' 73 << cet::demangle_symbol(
typeid(decltype(*opts.policy)).name()) <<
'\n' 74 <<
"# Path : \"" << opts.lookup_path <<
"\"\n\n" 75 << pset.to_indented_string(0, opts.mode);
82 std::variant<Options, Help>
83 process_arguments(
int argc,
char** argv)
85 namespace bpo = boost::program_options;
90 bool prefix_annotate{
false};
92 bpo::options_description desc(
"fhicl-dump [-c] <file>\nOptions");
95 (
"help,h",
"produce this help message")
96 (
"config,c", bpo::value<std::string>(&opts.input_filename),
"input file")
97 (
"output,o", bpo::value<std::string>(&opts.output_filename),
98 "output file (default is STDOUT)")
100 bpo::bool_switch(&annotate),
101 "include source location annotations")
103 bpo::bool_switch(&prefix_annotate),
104 "include source location annotations on line preceding parameter " 105 "assignment (mutually exclusive with 'annotate' option)")
106 (
"quiet,q",
"suppress output to STDOUT")
108 bpo::value<string>()->default_value(
"permissive"),
"see --supported-policies")
110 bpo::value<std::string>(&opts.lookup_path)->default_value(fhicl_env_var),
111 "path or environment variable to be used by lookup-policy")
112 (
"supported-policies",
"list the supported file lookup policies");
115 bpo::positional_options_description p;
118 auto const vm = cet::parsed_program_options(argc, argv, desc, p);
120 if (vm.count(
"help")) {
121 std::ostringstream os;
123 return Help{os.str()};
126 cet::lookup_policy_selector
const supported_policies{};
127 if (vm.count(
"supported-policies")) {
128 return Help{supported_policies.help_message()};
131 if (vm.count(
"quiet")) {
132 if (annotate || prefix_annotate) {
133 throw cet::exception(config) <<
"Cannot specify both '--quiet' and " 134 "'--(prefix-)annotate' options.\n";
139 if (annotate && prefix_annotate) {
140 throw cet::exception(config) <<
"Cannot specify both '--annotate' and " 141 "'--prefix-annotate' options.\n";
144 if (vm.count(
"lookup-policy") > 0) {
145 opts.policy = supported_policies.select(
146 vm[
"lookup-policy"].as<std::string>(), opts.lookup_path);
154 if (!vm.count(
"config")) {
155 std::ostringstream err_stream;
156 err_stream <<
"\nMissing input configuration file.\n\n" << desc <<
'\n';
static ParameterSet make(intermediate_table const &tbl)
int main(int argc, char **argv)
cet::coded_exception< error, detail::translate > exception