aboutsummaryrefslogtreecommitdiff
path: root/src/commandline.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/commandline.cpp')
-rw-r--r--src/commandline.cpp135
1 files changed, 0 insertions, 135 deletions
diff --git a/src/commandline.cpp b/src/commandline.cpp
deleted file mode 100644
index 6082686..0000000
--- a/src/commandline.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "commandline.h"
-#include "version.h"
-#include <configuration.h>
-#include <iomanip>
-#include <iostream>
-
-inline std::string optionText(const QStringList &opts)
-{
- std::string r;
- for(auto i = opts.constBegin(); i != opts.constEnd(); ) {
- if(i->length() == 1) {
- r.append("-" + i->toStdString());
- } else {
- r.append("--" + i->toStdString());
- }
-
- ++i;
- if(i != opts.constEnd()) {
- r.append(", ");
- }
- }
- return r;
-}
-
-inline void printOption(const QCommandLineOption &option)
-{
- std::cout << " "
- << std::setw(18) << std::left << optionText(option.names())
- << std::setw(32) << std::left << option.description().toStdString()
- << std::setw(18) << std::left << option.defaultValues().join(", ").toStdString()
- << std::endl;
-}
-
-constexpr const char *socketPath()
-{
-#if defined(Q_OS_UNIX)
- // could be a path such as "/tmp/foo"
- return "/tmp/smolbote.socket";
-#elif defined(Q_OS_WIN32)
- // could be a pipe path such as "\\.\pipe\foo"
- return "\\\\.\\pipe\\smolbote_socket";
-#endif
-}
-
-CommandLine::CommandLine()
- : QCommandLineParser()
- , helpOption(addHelpOption())
- , versionOption(addVersionOption())
- , buildOption("build", "Displays build information.")
- , configOption({ "c", "config" }, "Sets configuration file.", "path", Configuration::defaultUserConfigLocation())
- , profileOption({ "p", "profile" }, "Sets default profile.", "profile", "")
- , socketOption("socket", "Sets local socket.", "name", socketPath())
- , newWindowOption("in-new-window", "Open URL in new window")
-{
- setApplicationDescription("yet another no-frills browser");
-
- addOption(buildOption);
- addOption(configOption);
- addOption(profileOption);
- addOption(socketOption);
- addOption(newWindowOption);
-
- addPositionalArgument("URL", "URL(s) to open");
-}
-
-void CommandLine::parseCommandLine(const QCoreApplication &app)
-{
- QCommandLineParser::parse(app.arguments());
-
- application = const_cast<QCoreApplication *>(&app);
-
- if(isSet(helpOption)) {
- printHelp();
- }
-
- if(isSet(versionOption)) {
- printVersion();
- }
-
- if(isSet(buildOption)) {
- printBuild();
- }
-}
-
-void CommandLine::printHelp(int exitCode)
-{
- std::cout << "Usage: " << application->arguments().at(0).toStdString() << " [options] URL" << std::endl;
- std::cout << application->applicationName().toStdString() << " " << SMOLBOTE_DESCRIBE << ": "
- << applicationDescription().toStdString() << std::endl
- << std::endl;
-
- std::cout << "Options: " << std::endl;
- printOption(helpOption);
- printOption(versionOption);
- printOption(buildOption);
- printOption(configOption);
- printOption(profileOption);
- printOption(socketOption);
- printOption(newWindowOption);
- std::cout << std::endl;
-
- std::cout << "You can also overwrite configuration options using the syntax: " << std::endl
- << "--browser.setting.path=value" << std::endl
- << "More information on available keys can be found on the manual page." << std::endl
- << std::endl;
-
- std::cout << "Arguments: " << std::endl;
- std::cout << "- "
- << std::setw(20) << std::left << "URL"
- << std::setw(40) << std::left << "URL(s) to open"
- << std::endl
- << std::endl;
-
- exit(exitCode);
-}
-
-void CommandLine::printVersion(int exitCode)
-{
- std::cout << application->applicationName().toStdString() << " " << SMOLBOTE_DESCRIBE << std::endl;
- exit(exitCode);
-}
-
-void CommandLine::printBuild(int exitCode)
-{
- std::cout << SMOLBOTE_BRANCH << ":" << SMOLBOTE_COMMIT << std::endl;
- exit(exitCode);
-}