KWallet

kwallet-query/src/main.cpp
1/*
2 This file is part of the KDE
3 SPDX-FileCopyrightText: 2015 Valentin Rusu <kde@rusu.info>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include <QCommandLineParser>
9#include <QStringList>
10#include <iostream>
11
12#include <KAboutData>
13#include <KLocalizedString>
14
15#include "querydriver.h"
16
17int main(int argc, char *argv[])
18{
20
21 QueryDriver app(argc, argv);
22
23 KAboutData aboutData(QStringLiteral("kwallet-query"),
24 i18n("KWallet query interface"),
25 QStringLiteral("0.1"),
26 i18n("KWallet query interface"),
28 i18n("(c) 2015, The KDE Developers"));
29
30 QCommandLineParser cmdParser;
31 // clang-format off
32 QCommandLineOption verboseOption(QStringList() << QStringLiteral("v") << QStringLiteral("verbose"), i18n("verbose output"));
33 QCommandLineOption listOption(QStringList() << QStringLiteral("l") << QStringLiteral("list-entries"), i18n("list password entries"));
34 QCommandLineOption readOption(QStringList() << QStringLiteral("r") << QStringLiteral("read-password"), i18n("reads the secrets from the given <entry>"), i18n("Entry"));
35 QCommandLineOption writeOption(QStringList() << QStringLiteral("w") << QStringLiteral("write-password"), i18n("write secrets to the given <entry>. The values are read from the standard input. IMPORTANT: previous wallet entry value will be overwritten!"), i18n("Entry"));
36 QCommandLineOption folderOption(QStringList() << QStringLiteral("f") << QStringLiteral("folder"), i18n("specify the folder in the wallet <folder>"), i18n("Folder"));
37 // clang-format on
38
39 cmdParser.addHelpOption();
40 cmdParser.addPositionalArgument("wallet", i18n("The wallet to query"));
41 cmdParser.addOption(listOption);
42 cmdParser.addOption(readOption);
43 cmdParser.addOption(writeOption);
44 cmdParser.addOption(folderOption);
45 cmdParser.addOption(verboseOption);
46 cmdParser.process(app);
47
48 const QStringList args = cmdParser.positionalArguments();
49 if (args.empty()) {
50 std::cout << i18n("Missing argument").toStdString() << std::endl;
51 return 1;
52 }
53 if (args.count() > 1) {
54 std::cout << i18n("Too many arguments given").toStdString() << std::endl;
55 return 1;
56 }
57 app.setWalletName(args.first());
58 if (cmdParser.isSet(listOption) && cmdParser.isSet(readOption) && cmdParser.isSet(writeOption)) {
59 std::cout << i18n("Only one mode (list, read or write) can be set. Aborting").toStdString() << std::endl;
60 return 1;
61 }
62 if (!cmdParser.isSet(listOption) && !cmdParser.isSet(readOption) && !cmdParser.isSet(writeOption)) {
63 std::cout << i18n("Please specify the mode (list or read).").toStdString() << std::endl;
64 return 1;
65 }
66 if (cmdParser.isSet(listOption)) {
67 app.setMode(QueryDriver::List);
68 }
69 if (cmdParser.isSet(readOption)) {
70 app.setEntryName(cmdParser.value(readOption));
71 app.setMode(QueryDriver::Read);
72 }
73 if (cmdParser.isSet(writeOption)) {
74 app.setEntryName(cmdParser.value(writeOption));
75 app.setMode(QueryDriver::Write);
76 }
77 if (cmdParser.isSet(folderOption)) {
78 app.setEntryFolder(cmdParser.value(folderOption));
79 }
80 if (cmdParser.isSet(verboseOption)) {
81 app.setVerbose();
82 }
83
84 return app.exec();
85}
static void setApplicationDomain(const QByteArray &domain)
QString i18n(const char *text, const TYPE &arg...)
QCommandLineOption addHelpOption()
bool addOption(const QCommandLineOption &option)
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
bool isSet(const QCommandLineOption &option) const const
QStringList positionalArguments() const const
void process(const QCoreApplication &app)
QString value(const QCommandLineOption &option) const const
qsizetype count() const const
bool empty() const const
T & first()
std::string toStdString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:05 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.