/* Copyright© 2021 John Sennesael UsenetSearch is Free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. UsenetSearch 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 General Public License for more details. You should have received a copy of the GNU General Public License along with UsenetSearch. If not, see . */ #pragma once #include "usenetsearch/Configuration.h" #include "usenetsearch/Database.h" #include "usenetsearch/Filter.h" #include #include #include namespace usenetsearch { enum class CommandLineOptionType { Boolean, Integer, Path, String }; struct CommandLineOption { virtual ~CommandLineOption() = default; CommandLineOptionType type; char option; std::string helpText; }; template struct CommandLineOptionValue: public CommandLineOption { virtual ~CommandLineOptionValue() = default; T value; std::function onParse; }; class Application { bool m_canRun{false}; std::vector> m_commandLineArguments; Configuration m_config; std::string m_configFile{"usenetsearch.conf"}; Database m_db; Filter m_filter; void ExecuteCustomOption( std::shared_ptr&, const std::string& value="" ); void ParseArgs(int argc, char* argv[]); public: Application(); void AddBooleanOption( char option, const std::string& help, std::function onParse, bool defaultValue = false ); void AddFileOption( char option, const std::string& help, std::function onParse, std::filesystem::path defaultValue = "." ); void AddIntegerOption( char option, const std::string& help, std::function onParse, int defaultValue = 0 ); void AddStringOption( char option, const std::string& help, std::function onParse, std::string defaultValue = "" ); bool CanRun() const; Configuration& GetConfig(); Database& GetDb(); Filter& GetFilter(); bool Init(int argc, char* argv[]); void Usage(const std::string& programName); }; } // namespace usenetsearch