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"};
42 string input_filename;
43 std::unique_ptr<cet::filepath_maker> policy;
47 std::variant<Options, Help> process_arguments(
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);
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;
120 if (vm.count(
"help")) {
121 std::ostringstream os;
123 return Help{os.str()};
127 if (vm.count(
"supported-policies")) {
131 if (vm.count(
"quiet")) {
132 if (annotate || prefix_annotate) {
134 "'--(prefix-)annotate' options.\n";
139 if (annotate && prefix_annotate) {
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';
ostream_handle select_stream(std::string const &filename, std::ostream &default_os)
boost::program_options::variables_map parsed_program_options(int argc, char **argv, boost::program_options::options_description const &desc, boost::program_options::positional_options_description const &pos={})
void msg(const char *fmt,...)
static ParameterSet make(intermediate_table const &tbl)
int main(int argc, char **argv)
cet::coded_exception< error, detail::translate > exception
std::string help_message() const