18
#include "RemoveGroup.h"
21
#include "core/Group.h"
22
#include "core/Metadata.h"
24
#include <QCommandLineParser>
26
RemoveGroup::RemoveGroup()
28
name = QString("rmdir");
29
description = QString("Removes a group from a database.");
30
positionalArguments.append({QString("group"), QObject::tr("Path of the group to remove."), QString("")});
33
RemoveGroup::~RemoveGroup() = default;
35
int RemoveGroup::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
37
auto& out = parser->isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT;
38
auto& err = Utils::STDERR;
40
QString groupPath = parser->positionalArguments().at(1);
43
QPointer<Group> group = database->rootGroup()->findGroupByPath(groupPath);
45
err << QObject::tr("Group %1 not found.").arg(groupPath) << endl;
49
if (group == database->rootGroup()) {
50
err << QObject::tr("Cannot remove root group from database.") << endl;
55
auto* recycleBin = database->metadata()->recycleBin();
56
if (!database->metadata()->recycleBinEnabled() || (recycleBin && recycleBin->findGroupByUuid(group->uuid()))) {
60
database->recycleGroup(group);
64
if (!database->save(Database::Atomic, {}, &errorMessage)) {
65
err << QObject::tr("Unable to save database to file: %1").arg(errorMessage) << endl;
70
out << QObject::tr("Successfully recycled group %1.").arg(groupPath) << endl;
72
out << QObject::tr("Successfully deleted group %1.").arg(groupPath) << endl;