From e43cf73d33d731b5d817d98c3dcb3d66eba1f718 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 15 May 2018 19:17:51 +0200 Subject: Move help and version functions to main (out of Configuration) Make loading profiles a free function in Browser --- lib/configuration/configuration.cpp | 19 +++---------------- lib/configuration/configuration.h | 29 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp index 1829a5e..def997d 100644 --- a/lib/configuration/configuration.cpp +++ b/lib/configuration/configuration.cpp @@ -45,6 +45,7 @@ Configuration::Configuration() commandLine_desc.add_options() ("help,h", "Display this help.") ("version,v", "Display version information.") + ("build", "Display build branch and commit.") ("config,c", po::value()->default_value(defaultUserConfigLocation()), "Set the configuration file.") ("socket,s", po::value()->default_value(defaultSocketPath()), "Local server socket") @@ -122,7 +123,7 @@ Configuration::Configuration() Configuration::~Configuration() = default; -bool Configuration::parseConfigFile(const std::string &path) +bool Configuration::parse(const std::string &path) { std::ifstream f(path, std::ifstream::in); @@ -131,7 +132,7 @@ bool Configuration::parseConfigFile(const std::string &path) return true; } -bool Configuration::parseCommandLine(int argc, char **argv) +bool Configuration::parse(int argc, char **argv) { try { auto cmd = po::command_line_parser(argc, argv); @@ -145,20 +146,6 @@ bool Configuration::parseCommandLine(int argc, char **argv) return false; } - if(vm.count("help")) { - std::cout << qUtf8Printable(qApp->applicationName()) << " " << qUtf8Printable(qApp->applicationVersion()) << ": yet another no-frills browser" << std::endl; - std::cout << "Usage: " << qUtf8Printable(qApp->arguments().at(0)) << " [options] URL(s)" << std::endl; - - std::cout << std::endl << "Command-line Options: " << std::endl << commandLine_desc << std::endl; - std::cout << std::endl << "Configuration Options: " << std::endl << configuration_desc << std::endl; - exit(0); - } - - if(vm.count("version")) { - std::cout << qUtf8Printable(qApp->applicationName()) << " " << qUtf8Printable(qApp->applicationVersion()) << std::endl; - exit(0); - } - return true; } diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h index af75122..1d0fb54 100644 --- a/lib/configuration/configuration.h +++ b/lib/configuration/configuration.h @@ -23,8 +23,17 @@ public: explicit Configuration(); ~Configuration(); - bool parseConfigFile(const std::string &path); - bool parseCommandLine(int argc, char **argv); + bool parse(const std::string &path); + bool parse(int argc, char **argv); + + const std::vector> &options() + { + return configuration_desc.options(); + } + + bool exists(const char *path) { + return vm.count(path) ? true : false; + } template std::optional value(const char *path) const @@ -64,12 +73,6 @@ public: return std::optional(vm[path].as()); } - const std::vector> &options() - { - return configuration_desc.options(); - } - - QHash section(const std::string &prefix) const; QStringList positionalArguments() const { QStringList l; @@ -82,6 +85,16 @@ public: return l; } + QHash section(const std::string &prefix) const; + const boost::program_options::options_description commandlineOptions() const + { + return commandLine_desc; + } + const boost::program_options::options_description configurationOptions() const + { + return configuration_desc; + } + private: boost::program_options::options_description commandLine_desc; boost::program_options::options_description configuration_desc; -- cgit v1.2.1