Rework option parsing a bit.
- Add --basic-regexp - Add --grep - Remove --input-file - Make it possible to have multiple --regexp
This commit is contained in:
parent
a86baf750f
commit
03e07dfc3e
|
@ -70,6 +70,14 @@ int main(int argc, char *argv[])
|
|||
cout << "perl-regexp: " << vm.count("perl-regexp") << '\n';
|
||||
cout << "ignore-case: " << vm.count("ignore-case") << '\n';
|
||||
|
||||
if (vm.count("regexp") > 0)
|
||||
{
|
||||
for (const auto ®ex : vm["regexp"].as<std::vector<std::string>>())
|
||||
{
|
||||
cout << "Searching for: " << regex << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
if (vm.count("input-file") > 0)
|
||||
{
|
||||
cout << "\nINPUT FILES:\n";
|
||||
|
|
|
@ -41,40 +41,52 @@ using std::cout;
|
|||
|
||||
po::variables_map parse_options(int argc, char *argv[])
|
||||
{
|
||||
po::options_description cmdline_desc(translate("Available options"));
|
||||
po::options_description options_visible(translate("Available options"));
|
||||
// clang-format off
|
||||
cmdline_desc.add_options()
|
||||
options_visible.add_options()
|
||||
("help,h",
|
||||
translate("Display this help and exit.").str().data())
|
||||
("version,V",
|
||||
translate("Display version information and exit.").str().data())
|
||||
("basic-regexp,G",
|
||||
translate("PATTERN is a basic regular expression (default).")
|
||||
.str().data())
|
||||
("extended-regexp,E",
|
||||
translate("PATTERN is extended regular expression.").str().data())
|
||||
translate("PATTERN is an extended regular expression.").str().data())
|
||||
("grep",
|
||||
translate("Use grep-variation of regular expressions with -G and -E.")
|
||||
.str().data())
|
||||
("perl-regexp,P",
|
||||
translate("PATTERN is Perl regular expression.").str().data())
|
||||
translate("PATTERN is a Perl regular expression.").str().data())
|
||||
("ignore-case,i",
|
||||
translate("Ignore case distinctions in pattern and data.")
|
||||
.str().data())
|
||||
("regexp,e", po::value<std::string>()->value_name(translate("PATTERN")),
|
||||
translate("Use PATTERN for matching.").str().data())
|
||||
("input-file,I", po::value<std::vector<std::string>>()
|
||||
->value_name(translate("FILE")),
|
||||
translate("Input file. Can be used more than once.").str().data())
|
||||
("regexp,e", po::value<std::vector<std::string>>()->composing()
|
||||
->value_name(translate("PATTERN")),
|
||||
translate("Use additional PATTERN for matching.").str().data())
|
||||
;
|
||||
|
||||
po::options_description options_hidden("Hidden options");
|
||||
options_hidden.add_options()
|
||||
("input-file", po::value<std::vector<std::string>>()
|
||||
->value_name("FILE"), "Input file to search.")
|
||||
;
|
||||
// clang-format on
|
||||
po::options_description options_all("Allowed options");
|
||||
options_all.add(options_visible).add(options_hidden);
|
||||
|
||||
po::positional_options_description positional_desc;
|
||||
positional_desc.add("regexp", 1).add("input-file", -1);
|
||||
|
||||
po::variables_map vm;
|
||||
po::store(po::command_line_parser(argc, argv)
|
||||
.options(cmdline_desc)
|
||||
.options(options_all)
|
||||
.positional(positional_desc)
|
||||
.run(),
|
||||
vm);
|
||||
|
||||
std::ifstream configfile(get_config_path());
|
||||
po::store(po::parse_config_file(configfile, cmdline_desc, true), vm);
|
||||
po::store(po::parse_config_file(configfile, options_visible, true), vm);
|
||||
configfile.close();
|
||||
|
||||
po::notify(vm);
|
||||
|
@ -82,7 +94,7 @@ po::variables_map parse_options(int argc, char *argv[])
|
|||
if (vm.count("help") != 0)
|
||||
{
|
||||
cout << translate("Usage: epubgrep [OPTION]… PATTERN [FILE]…\n");
|
||||
cout << cmdline_desc;
|
||||
cout << options_visible;
|
||||
}
|
||||
else if (vm.count("version") != 0)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user