Make options::options printable (for use in debug output).
This commit is contained in:
parent
a8db304bf1
commit
017059cb5b
|
@ -26,6 +26,8 @@
|
|||
#include <boost/program_options/positional_options.hpp>
|
||||
#include <boost/program_options/value_semantic.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/ostream.h> // For compatibility with fmt 4.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
@ -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
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -56,6 +57,9 @@ struct options
|
|||
std::vector<std::string> 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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user