Skip to content

Commit

Permalink
CLI: Renaming extract -> export
Browse files Browse the repository at this point in the history
  • Loading branch information
louib authored and louib committed Aug 19, 2019
1 parent aca981b commit 834d605
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Drop to background when copy feature [#3253]
- Fix password generator issues with special characters [#3303]
- CLI: Add '--format' option and CSV support to the 'extract' command [#3277]
- 💥💥 CLI: Renamed command `extract` -> `export`. [#3277]

2.4.3 (2019-06-12)
=========================
Expand Down
2 changes: 1 addition & 1 deletion src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set(cli_SOURCES
Diceware.cpp
Edit.cpp
Estimate.cpp
Extract.cpp
Export.cpp
Generate.cpp
List.cpp
Locate.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/cli/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "Diceware.h"
#include "Edit.h"
#include "Estimate.h"
#include "Extract.h"
#include "Export.h"
#include "Generate.h"
#include "List.h"
#include "Locate.h"
Expand Down Expand Up @@ -114,7 +114,7 @@ void populateCommands()
commands.insert(QString("diceware"), new Diceware());
commands.insert(QString("edit"), new Edit());
commands.insert(QString("estimate"), new Estimate());
commands.insert(QString("extract"), new Extract());
commands.insert(QString("export"), new Export());
commands.insert(QString("generate"), new Generate());
commands.insert(QString("locate"), new Locate());
commands.insert(QString("ls"), new List());
Expand Down
21 changes: 11 additions & 10 deletions src/cli/Extract.cpp → src/cli/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,38 @@
#include <cstdlib>
#include <stdio.h>

#include "Extract.h"
#include "Export.h"

#include "cli/TextStream.h"
#include "cli/Utils.h"
#include "core/Database.h"
#include "format/CsvExporter.h"

const QCommandLineOption Extract::FormatOption =
const QCommandLineOption Export::FormatOption =
QCommandLineOption(QStringList() << "f"
<< "format",
QObject::tr("Format to use when extracting. Available choices are xml or csv. Defaults to xml."),
QObject::tr("Format to use when exporting. Available choices are xml or csv. Defaults to xml."),
QObject::tr("xml|csv"));

Extract::Extract()
Export::Export()
{
name = QString("extract");
options.append(Extract::FormatOption);
description = QObject::tr("Extract and print the content of a database.");
name = QString("export");
options.append(Export::FormatOption);
description = QObject::tr("Exports the content of a database to standard output in the specified format.");
}

int Extract::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)

int Export::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
{
TextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly);

QString format = parser->value(Extract::FormatOption);
QString format = parser->value(Export::FormatOption);
if (format.isEmpty() || format == QString("xml")) {
QByteArray xmlData;
QString errorMessage;
if (!database->extract(xmlData, &errorMessage)) {
errorTextStream << QObject::tr("Unable to extract database to XML: %1").arg(errorMessage) << endl;
errorTextStream << QObject::tr("Unable to export database to XML: %1").arg(errorMessage) << endl;
return EXIT_FAILURE;
}
outputTextStream << xmlData.constData() << endl;
Expand Down
10 changes: 5 additions & 5 deletions src/cli/Extract.h → src/cli/Export.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KEEPASSXC_EXTRACT_H
#define KEEPASSXC_EXTRACT_H
#ifndef KEEPASSXC_EXPORT_H
#define KEEPASSXC_EXPORT_H

#include "DatabaseCommand.h"

class Extract : public DatabaseCommand
class Export : public DatabaseCommand
{
public:
Extract();
Export();

int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;

static const QCommandLineOption FormatOption;
};

#endif // KEEPASSXC_EXTRACT_H
#endif // KEEPASSXC_EXPORT_H
8 changes: 4 additions & 4 deletions src/cli/keepassxc-cli.1
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Edits a database entry. A password can be generated (\fI-g\fP option), or a prom
.IP "estimate [options] [password]"
Estimates the entropy of a password. The password to estimate can be provided as a positional argument, or using the standard input.

.IP "extract [options] <database>"
Extracts and prints the contents of a database to standard output in the specified format (defaults to XML).
.IP "export [options] <database>"
Exports the content of a database to standard output in the specified format (defaults to XML).

.IP "generate [options]"
Generate a random password.
Expand Down Expand Up @@ -163,10 +163,10 @@ otherwise the program will fail. If the wordlist has < 4000 words a warning will
be printed to STDERR.


.SS "Extract options"
.SS "Export options"

.IP "-f, --format"
Format to use when extracting. Available choices are xml or csv. Defaults to xml.
Format to use when exporting. Available choices are xml or csv. Defaults to xml.


.SS "List options"
Expand Down
22 changes: 11 additions & 11 deletions tests/TestCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "cli/Diceware.h"
#include "cli/Edit.h"
#include "cli/Estimate.h"
#include "cli/Extract.h"
#include "cli/Export.h"
#include "cli/Generate.h"
#include "cli/List.h"
#include "cli/Locate.h"
Expand Down Expand Up @@ -170,7 +170,7 @@ void TestCli::testCommand()
QVERIFY(Command::getCommand("diceware"));
QVERIFY(Command::getCommand("edit"));
QVERIFY(Command::getCommand("estimate"));
QVERIFY(Command::getCommand("extract"));
QVERIFY(Command::getCommand("export"));
QVERIFY(Command::getCommand("generate"));
QVERIFY(Command::getCommand("locate"));
QVERIFY(Command::getCommand("ls"));
Expand Down Expand Up @@ -655,14 +655,14 @@ void TestCli::testEstimate()
}
}

void TestCli::testExtract()
void TestCli::testExport()
{
Extract extractCmd;
QVERIFY(!extractCmd.name.isEmpty());
QVERIFY(extractCmd.getDescriptionLine().contains(extractCmd.name));
Export exportCmd;
QVERIFY(!exportCmd.name.isEmpty());
QVERIFY(exportCmd.getDescriptionLine().contains(exportCmd.name));

Utils::Test::setNextPassword("a");
extractCmd.execute({"extract", m_dbFile->fileName()});
exportCmd.execute({"export", m_dbFile->fileName()});

m_stdoutFile->seek(0);
m_stdoutFile->readLine(); // skip prompt line
Expand All @@ -683,19 +683,19 @@ void TestCli::testExtract()
qint64 pos = m_stdoutFile->pos();
qint64 posErr = m_stderrFile->pos();
Utils::Test::setNextPassword("a");
extractCmd.execute({"extract", "-f", "xml", "-q", m_dbFile->fileName()});
exportCmd.execute({"export", "-f", "xml", "-q", m_dbFile->fileName()});
m_stdoutFile->seek(pos);
m_stderrFile->seek(posErr);
reader.readDatabase(m_stdoutFile.data(), dbQuiet.data());
QVERIFY(!reader.hasError());
QVERIFY(db.data());
QCOMPARE(m_stderrFile->readAll(), QByteArray(""));

// CSV extraction
// CSV exporting
pos = m_stdoutFile->pos();
posErr = m_stderrFile->pos();
Utils::Test::setNextPassword("a");
extractCmd.execute({"extract", "-f", "csv", m_dbFile->fileName()});
exportCmd.execute({"export", "-f", "csv", m_dbFile->fileName()});
m_stdoutFile->seek(pos);
m_stdoutFile->readLine(); // skip prompt line
m_stderrFile->seek(posErr);
Expand All @@ -710,7 +710,7 @@ void TestCli::testExtract()
pos = m_stdoutFile->pos();
posErr = m_stderrFile->pos();
Utils::Test::setNextPassword("a");
extractCmd.execute({"extract", "-f", "yaml", m_dbFile->fileName()});
exportCmd.execute({"export", "-f", "yaml", m_dbFile->fileName()});
m_stdoutFile->seek(pos);
m_stdoutFile->readLine(); // skip prompt line
m_stderrFile->seek(posErr);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCli.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private slots:
void testEdit();
void testEstimate_data();
void testEstimate();
void testExtract();
void testExport();
void testGenerate_data();
void testGenerate();
void testKeyFileOption();
Expand Down

0 comments on commit 834d605

Please sign in to comment.