diff --git a/src/options.cpp b/src/options.cpp index ea1093e..59000e9 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include // For compatibility with fmt 4. #include #include @@ -42,6 +44,7 @@ namespace epubgrep::options namespace po = boost::program_options; using boost::locale::translate; +using fmt::format; using std::cout; options parse_options(int argc, char *argv[]) @@ -243,4 +246,66 @@ options parse_again(const po::variables_map &vm) return opts; } +std::ostream &operator<<(std::ostream &out, const options &opts) +{ + const std::string regex_kind{[&opts] + { + switch (opts.regex) + { + case regex_kind::basic: + { + return "basic"; + break; + } + case regex_kind::extended: + { + return "extended"; + break; + } + case regex_kind::perl: + { + return "perl"; + break; + } + } + return "error"; + }()}; + out << format("help={0:} version={1:} regex={2:s} grep={3:} " + "ignore_case={4:} ", + opts.help, opts.version, regex_kind, opts.grep, + opts.ignore_case); + + out << "regexp={"; + for (const auto ®exp : opts.regexp) + { + if (regexp != *opts.regexp.begin()) + { + out << ", "; + } + out << '"' << regexp << '"'; + } + out << "} "; + + out << format("raw={0:} context={1:d} nocolor={2:} no_fn_fs={3:} " + "no_fn_epub={4:} recursive={5:} dereference_recursive={6:} ", + opts.raw, opts.context, opts.nocolor, opts.no_fn_fs, + opts.no_fn_epub, opts.recursive, opts.dereference_recursive); + + out << "input_file={"; + for (const auto &input_file : opts.input_file) + { + if (input_file != *opts.input_file.begin()) + { + out << ", "; + } + out << '"' << input_file << '"'; + } + out << "} "; + + out << format("ignore_archive={0:} debug={1:}", opts.ignore_archive_errors, + opts.debug); + + return out; +} + } // namespace epubgrep::options diff --git a/src/options.hpp b/src/options.hpp index 68506b5..45ea893 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -56,6 +57,9 @@ struct options std::vector input_file; bool ignore_archive_errors{false}; bool debug{false}; + + //! For the debug output. + friend std::ostream &operator<<(std::ostream &out, const options &opts); }; //! Parse options and return them.