Add --regexp and --input, add both as positional options.
This commit is contained in:
parent
dd7a62ceb8
commit
9a136b87a9
12
src/main.cpp
12
src/main.cpp
|
@ -24,6 +24,8 @@
|
|||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -58,4 +60,14 @@ int main(int argc, char *argv[])
|
|||
cout << "extended-regexp: " << vm.count("extended-regexp") << '\n';
|
||||
cout << "perl-regexp: " << vm.count("perl-regexp") << '\n';
|
||||
cout << "ignore-case: " << vm.count("ignore-case") << '\n';
|
||||
|
||||
if (vm.count("input") > 0)
|
||||
{
|
||||
cout << "\nINPUT FILES: ";
|
||||
for (const auto &input : vm["input"].as<std::vector<std::string>>())
|
||||
{
|
||||
cout << input << " ";
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <boost/locale/message.hpp>
|
||||
#include <boost/program_options/options_description.hpp>
|
||||
#include <boost/program_options/parsers.hpp>
|
||||
#include <boost/program_options/positional_options.hpp>
|
||||
#include <boost/program_options/value_semantic.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
|
@ -39,35 +41,48 @@ using std::cout;
|
|||
|
||||
po::variables_map parse_options(int argc, char *argv[])
|
||||
{
|
||||
po::options_description desc(translate("Available options"));
|
||||
po::options_description cmdline_desc(translate("Available options"));
|
||||
// clang-format off
|
||||
desc.add_options()
|
||||
cmdline_desc.add_options()
|
||||
("help",
|
||||
translate("Display this help and exit").str().data())
|
||||
translate("Display this help and exit.").str().data())
|
||||
("version",
|
||||
translate("Display version information and exit").str().data())
|
||||
translate("Display version information and exit.").str().data())
|
||||
("extended-regexp",
|
||||
translate("PATTERNS are extended regular expressions").str().data())
|
||||
translate("PATTERN is extended regular expression.").str().data())
|
||||
("perl-regexp",
|
||||
translate("PATTERNS are Perl regular expressions").str().data())
|
||||
translate("PATTERN is Perl regular expression.").str().data())
|
||||
("ignore-case",
|
||||
translate("Ignore case distinctions in patterns and data")
|
||||
translate("Ignore case distinctions in pattern and data.")
|
||||
.str().data())
|
||||
("regexp", po::value<std::string>()->value_name(translate("PATTERN")),
|
||||
translate("Use PATTERN for matching.").str().data())
|
||||
("input", po::value<std::vector<std::string>>()
|
||||
->value_name(translate("FILE")),
|
||||
translate("Input files. Can be repeated.").str().data())
|
||||
;
|
||||
// clang-format on
|
||||
|
||||
po::positional_options_description positional_desc;
|
||||
positional_desc.add("regexp", 1).add("input", -1);
|
||||
|
||||
po::variables_map vm;
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
po::store(po::command_line_parser(argc, argv)
|
||||
.options(cmdline_desc)
|
||||
.positional(positional_desc)
|
||||
.run(),
|
||||
vm);
|
||||
|
||||
std::ifstream configfile(get_config_path());
|
||||
po::store(po::parse_config_file(configfile, desc, true), vm);
|
||||
po::store(po::parse_config_file(configfile, cmdline_desc, true), vm);
|
||||
configfile.close();
|
||||
|
||||
po::notify(vm);
|
||||
|
||||
if (vm.count("help") != 0)
|
||||
{
|
||||
cout << translate("Usage: epubgrep [OPTION]… PATTERNS [FILE]…\n");
|
||||
cout << desc;
|
||||
cout << translate("Usage: epubgrep [OPTION]… PATTERN [FILE]…\n");
|
||||
cout << cmdline_desc;
|
||||
}
|
||||
else if (vm.count("version") != 0)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user