Public Member Functions | Private Member Functions | Private Attributes | List of all members
art::BasicOptionsHandler Class Reference

#include <BasicOptionsHandler.h>

Inheritance diagram for art::BasicOptionsHandler:
art::OptionsHandler

Public Member Functions

 BasicOptionsHandler (bpo::options_description &desc, cet::filepath_maker &maker, bool report_unused)
 
- Public Member Functions inherited from art::OptionsHandler
virtual ~OptionsHandler ()=default
 
int checkOptions (bpo::variables_map const &vm)
 
int processOptions (bpo::variables_map const &vm, fhicl::intermediate_table &raw_config)
 

Private Member Functions

int doCheckOptions (bpo::variables_map const &vm) override
 
int doProcessOptions (bpo::variables_map const &vm, fhicl::intermediate_table &raw_config) override
 

Private Attributes

bpo::options_description const & help_desc_
 
cet::filepath_makermaker_
 

Detailed Description

Definition at line 13 of file BasicOptionsHandler.h.

Constructor & Destructor Documentation

art::BasicOptionsHandler::BasicOptionsHandler ( bpo::options_description &  desc,
cet::filepath_maker maker,
bool  report_unused 
)

Definition at line 35 of file BasicOptionsHandler.cc.

38  : help_desc_{desc}, maker_{maker}
39 {
40  // clang-format off
41  desc.add_options()
42  ("help,h", "produce help message")
43  ("version", ("Print art version (" + pretty_version(art::getReleaseVersion()) + ")")
44  .c_str())
45  ("config,c", bpo::value<std::string>(), "Configuration file.")
46  ("process-name", bpo::value<std::string>(), "art process name.")
47  ("prune-config",
48  bpo::value<bool>()->default_value(true, to_string(true)),
49  "Remove unused modules and paths from the fully-processed configuration.")
50  ("report-unused",
51  bpo::value<bool>()->default_value(report_unused, to_string(report_unused)),
52  "If 'true', the list of unused modules and paths will be printed to STDERR.")
53  ("print-available",
54  bpo::value<std::string>(),
55  ("List all available plugins with the provided suffix. Choose from:"s +
56  Suffixes::print()).c_str())
57  ("print-available-modules",
58  "List all available modules that can be invoked in a FHiCL file.")
59  ("print-available-services",
60  "List all available services that can be invoked in a FHiCL file.")
61  ("print-description",
62  bpo::value<std::vector<std::string>>()->multitoken(),
63  "Print description of specified module, service, source, or other "
64  "plugin (multiple OK). Argument can be a regular expression used "
65  "to match the plugin specification. To narrow the search to "
66  "plugins with a particular suffix, preface the regular expression"
67  "with the suffix (e.g. service:TFileService).")
68  ("status-bar",
69  "Provide status bar that reports the progress of retrieving "
70  "plugin information for a 'print-available' command.");
71  // clang-format on
72 }
static std::string print()
std::string const & getReleaseVersion()
bpo::options_description const & help_desc_
cet::filepath_maker & maker_
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
static QCString * s
Definition: config.cpp:1042

Member Function Documentation

int art::BasicOptionsHandler::doCheckOptions ( bpo::variables_map const &  vm)
overrideprivatevirtual

Implements art::OptionsHandler.

Definition at line 75 of file BasicOptionsHandler.cc.

76 {
77  // Technically the "help" and "print*" options are processing steps,
78  // but we want to short-circuit.
79  if (vm.count("help")) {
80  // Could simply do cout << help_desc_, but the boost-provided
81  // printout does not add any left-hand padding. Will add a
82  // 2-space tab by hand.
83  std::stringstream ss;
84  ss << help_desc_; // Note NOT our own desc_.
85  for (std::string s; std::getline(ss, s);)
86  std::cout << std::string(2, ' ') << s << '\n';
87  std::cout << '\n';
88  return detail::info_success();
89  }
90  bool const status_bar = vm.count("status-bar") > 0;
91  if (vm.count("print-available")) {
92  detail::print_available_plugins(vm["print-available"].as<std::string>(),
93  status_bar);
94  return detail::info_success();
95  }
96  if (vm.count("print-available-modules")) {
98  return detail::info_success();
99  }
100  if (vm.count("print-available-services")) {
102  return detail::info_success();
103  }
104  if (status_bar) {
106  << "The '--status-bar' option can be used only with the "
107  "'--print-available*' program options.\n";
108  }
109 
110  if (vm.count("print-description")) {
112  vm["print-description"].as<std::vector<std::string>>());
113  return detail::info_success();
114  }
115  if (vm.count("version")) {
116  std::cout << "art " << pretty_version(getReleaseVersion()) << '\n';
117  return detail::info_success();
118  }
119 
120  if (!vm.count("config")) {
121  throw Exception(errors::Configuration) << "No configuration file given.\n";
122  }
123  return 0;
124 }
std::string string
Definition: nybbler.cc:12
static constexpr double as
Definition: Units.h:101
std::string const & getReleaseVersion()
void print_available_plugins(std::string const &suffix, std::string const &spec, bool verbose)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bpo::options_description const & help_desc_
void print_descriptions(std::vector< std::string > const &plugins)
static std::string const & service()
constexpr int info_success()
Definition: info_success.h:8
static std::string const & module()
static QCString * s
Definition: config.cpp:1042
int art::BasicOptionsHandler::doProcessOptions ( bpo::variables_map const &  vm,
fhicl::intermediate_table raw_config 
)
overrideprivatevirtual

Implements art::OptionsHandler.

Definition at line 127 of file BasicOptionsHandler.cc.

130 {
131  try {
132  raw_config = fhicl::parse_document(vm["config"].as<std::string>(), maker_);
133  }
134  catch (cet::exception& e) {
135  std::cerr << "Failed to parse the configuration file '"
136  << vm["config"].as<std::string>() << "' with exception\n"
137  << e.what() << "\n";
138  return 90;
139  }
140  if (raw_config.empty()) {
141  std::cerr << "INFO: provided configuration file '"
142  << vm["config"].as<std::string>() << "' is empty: \n"
143  << "using minimal defaults and command-line options.\n";
144  }
145  if (vm.count("process-name")) {
146  raw_config.put("process_name", vm["process-name"].as<std::string>());
147  }
148  if (vm.count("prune-config")) {
149  raw_config.put("services.scheduler.pruneConfig",
150  vm["prune-config"].as<bool>());
151  }
152  if (vm.count("report-unused")) {
153  raw_config.put("services.scheduler.reportUnused",
154  vm["report-unused"].as<bool>());
155  }
156  return 0;
157 }
std::string string
Definition: nybbler.cc:12
const double e
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
Definition: parse.cc:720
cet::filepath_maker & maker_
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

bpo::options_description const& art::BasicOptionsHandler::help_desc_
private

Definition at line 27 of file BasicOptionsHandler.h.

cet::filepath_maker& art::BasicOptionsHandler::maker_
private

Definition at line 28 of file BasicOptionsHandler.h.


The documentation for this class was generated from the following files: