Commit 2a4e02b6 authored by Rafał Malinowski's avatar Rafał Malinowski

core: add ExecutionArgumentsParser class

Signed-off-by: Rafał Malinowski's avatarRafał Malinowski <rafal.przemyslaw.malinowski@gmail.com>
parent 66f39cc9
set (execution-arguments_SRCS
execution-arguments.cpp
execution-arguments-builder.cpp
execution-arguments-parser.cpp
)
kadu_subdirectory (execution-arguments "${execution-arguments_SRCS}" "" "")
/*
* %kadu copyright begin%
* Copyright 2014 Rafał Malinowski (rafal.przemyslaw.malinowski@gmail.com)
* %kadu copyright end%
*
* This program 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 2 of
* the License, or (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "execution-arguments-parser.h"
#include "execution-arguments/execution-arguments.h"
#include "execution-arguments/execution-arguments-builder.h"
ExecutionArguments ExecutionArgumentsParser::parse(const QStringList &arguments) const
{
auto queryVersion = false;
auto queryUsage = false;
auto debugMask = QString{};
auto configurationDirectory = QString{};
auto openIds = QStringList{};
for (auto it = arguments.constBegin(); it != arguments.constEnd(); ++it)
{
if (*it == QLatin1String("--version"))
queryVersion = true;
else if (*it == QLatin1String("--help"))
queryUsage = true;
else if (*it == QLatin1String("--debug") && (it + 1) != arguments.constEnd())
debugMask = *(++it);
else if (*it == QLatin1String("--config-dir") && (it + 1) != arguments.constEnd())
configurationDirectory = *(++it);
else if (QRegExp("^[a-zA-Z]*:(/){0,3}.*").exactMatch(*it))
openIds.append(*it);
else
fprintf(stderr, "Ignoring unknown parameter '%s'\n", it->toUtf8().constData());
}
return ExecutionArgumentsBuilder{}
.setQueryVersion(queryVersion)
.setQueryUsage(queryUsage)
.setDebugMask(std::move(debugMask))
.setConfigurationDirectory(std::move(configurationDirectory))
.setOpenIds(std::move(openIds))
.build();
}
/*
* %kadu copyright begin%
* Copyright 2014 Rafał Malinowski (rafal.przemyslaw.malinowski@gmail.com)
* %kadu copyright end%
*
* This program 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 2 of
* the License, or (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "exports.h"
#include <QtCore/QStringList>
class ExecutionArguments;
class KADUAPI ExecutionArgumentsParser final
{
public:
ExecutionArguments parse(const QStringList &arguments) const;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment