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 Jun 23, 2019
1 parent a5aa4bd commit e091802
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Group sorting feature [#3282]
- CLI: Add 'flatten' option to the 'ls' command [#3276]
- 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 @@ -22,7 +22,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 @@ -28,7 +28,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 @@ -112,7 +112,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
22 changes: 11 additions & 11 deletions src/cli/Extract.cpp → src/cli/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,41 @@
#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.");
}

Extract::~Extract()
Export::~Export()
{
}

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
12 changes: 6 additions & 6 deletions src/cli/Extract.h → src/cli/Export.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
* 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();
~Extract();
Export();
~Export();

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

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 @@ -31,8 +31,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 @@ -150,10 +150,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 @@ -38,7 +38,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 @@ -167,7 +167,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 @@ -636,14 +636,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 @@ -664,19 +664,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 @@ -691,7 +691,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 @@ -48,7 +48,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 e091802

Please sign in to comment.