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

This commit is contained in:
Patrick Klein authored and GitHub committed 2021-12-07 23:40:09 -05:00
1 parent b3896f2600
commit a0a063b57f
9 files changed
+357 -211

No files matched your search

+16 -3
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;