epubgrep/src/options.cpp

70 lines
2.2 KiB
C++

/* This file is part of epubgrep.
* Copyright © 2021 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "options.hpp"
#include "version.hpp"
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include <iostream>
namespace epubgrep
{
namespace po = boost::program_options;
using std::cout;
po::variables_map parse_options(int argc, char *argv[])
{
po::options_description desc("Available options");
// clang-format off
desc.add_options()
("help", "Prints help information")
("version", "Prints version information")
("extended-regexp", "PATTERNS are extended regular expressions")
("perl-regexp", "PATTERNS are Perl regular expressions")
("ignore-case", "Ignore case distinctions in patterns and data")
;
// clang-format on
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help") != 0)
{
cout << "Usage: epubgrep [OPTION]… PATTERNS [FILE]…\n";
cout << desc << '\n';
}
else if (vm.count("version") != 0)
{
cout << "epubgrep " << epubgrep::version << '\n';
cout << "Copyright © 2021 tastytea <tastytea@tastytea.de>\n"
"License AGPLv3: GNU AGPL version 3 "
"<https://gnu.org/licenses/agpl.html>.\n"
"This program comes with ABSOLUTELY NO WARRANTY. This is free "
"software,\n"
"and you are welcome to redistribute it under certain "
"conditions.\n";
}
return vm;
}
} // namespace epubgrep