Add -i/--include option to "generate" CLI command. (#7112)

This commit is contained in:
Patrick Klein
2021-12-08 05:40:09 +01:00
committed by GitHub
parent b3896f2600
commit a0a063b57f
9 changed files with 359 additions and 213 deletions

View File

@@ -53,6 +53,12 @@ const QCommandLineOption Generate::ExcludeCharsOption = QCommandLineOption(QStri
QObject::tr("Exclude character set"),
QObject::tr("chars"));
const QCommandLineOption Generate::CustomCharacterSetOption =
QCommandLineOption(QStringList() << "c"
<< "custom",
QObject::tr("Use custom character set"),
QObject::tr("chars"));
const QCommandLineOption Generate::ExcludeSimilarCharsOption =
QCommandLineOption(QStringList() << "exclude-similar", QObject::tr("Exclude similar looking characters"));
@@ -71,6 +77,7 @@ Generate::Generate()
options.append(Generate::ExcludeCharsOption);
options.append(Generate::ExcludeSimilarCharsOption);
options.append(Generate::IncludeEveryGroupOption);
options.append(Generate::CustomCharacterSetOption);
}
/**
@@ -120,9 +127,15 @@ QSharedPointer<PasswordGenerator> Generate::createGenerator(QSharedPointer<QComm
// The default charset will be used if no explicit class
// option was set.
passwordGenerator->setCharClasses(classes);
passwordGenerator->setFlags(flags);
passwordGenerator->setExcludedChars(parser->value(Generate::ExcludeCharsOption));
if (flags != 0x0) {
passwordGenerator->setFlags(flags);
}
QString customCharacterSet = parser->value(Generate::CustomCharacterSetOption);
if (classes != 0x0 || !customCharacterSet.isNull()) {
passwordGenerator->setCharClasses(classes);
}
passwordGenerator->setCustomCharacterSet(customCharacterSet);
passwordGenerator->setExcludedCharacterSet(parser->value(Generate::ExcludeCharsOption));
if (!passwordGenerator->isValid()) {
err << QObject::tr("Invalid password generator after applying all options") << endl;

View File

@@ -39,6 +39,7 @@ public:
static const QCommandLineOption ExcludeCharsOption;
static const QCommandLineOption ExcludeSimilarCharsOption;
static const QCommandLineOption IncludeEveryGroupOption;
static const QCommandLineOption CustomCharacterSetOption;
};
#endif // KEEPASSXC_GENERATE_H