epubgrep/src/options.hpp

85 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/>.
*/
#ifndef EPUBGREP_OPTIONS_HPP
#define EPUBGREP_OPTIONS_HPP
#include "fs-compat.hpp"
#include <boost/program_options/variables_map.hpp>
#include <cstddef>
#include <cstdint>
#include <ostream>
#include <string>
#include <vector>
namespace epubgrep::options
{
namespace po = boost::program_options;
enum class regex_kind
{
basic,
extended,
perl
};
struct options
{
bool help{false};
bool version{false};
regex_kind regex{regex_kind::basic};
bool grep{false};
bool ignore_case{false};
std::vector<std::string> regexp;
bool raw{false};
std::uint64_t context{0};
bool nocolor{false};
bool no_fn_fs{false};
bool no_fn_epub{false};
bool recursive{false};
bool dereference_recursive{false};
std::vector<std::string> input_file;
bool ignore_archive_errors{false};
bool debug{false};
bool json{false};
bool html{false};
//! For the debug output.
friend std::ostream &operator<<(std::ostream &out, const options &opts);
};
//! Parse options and return them.
[[nodiscard]] options parse_options(int argc, char *argv[]);
/*!
* @brief Returns the path of the config file.
*
* If XDG_CONFIG_HOME is set: ${XDG_CONFIG_HOME}/epubgrep.conf
* If HOME is set: ${HOME}/.config/epubgrep.conf
* Otherwise: epubgrep.conf
*/
[[nodiscard]] fs::path get_config_path();
//! Parse variables map and return nice options struct.
[[nodiscard]] options parse_again(const po::variables_map &vm);
} // namespace epubgrep::options
#endif // EPUBGREP_OPTIONS_HPP