Skip to content

Commit

Permalink
Suppress unrecognized option warning for enable/disable options
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Mar 14, 2020
1 parent 085275b commit a06a3ca
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions src/qconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class ConfOpt {
}

QString name, arg, var, desc;
bool hidden = false; // invisible in usage
};

class ConfGen {
Expand Down Expand Up @@ -277,33 +278,36 @@ class ConfGen {
// extraopts += ConfOpt("disable-dnotify", "", "QC_DISABLE_DNOTIFY", "Disable Linux DNOTIFY.");
}

void addDepOption(const QString &name, const QString &arg, const QString &var, const QString &desc)
ConfOpt &addDepOption(const QString &name, const QString &arg, const QString &var, const QString &desc)
{
ConfOpt opt;
opt.name = name;
opt.arg = arg;
opt.var = var;
opt.desc = desc;
opt.name = name;
opt.arg = arg;
opt.var = var;
opt.desc = desc;
opt.hidden = desc.isEmpty();
depopts += opt;
return depopts.last();
}

void addAppOption(const QString &name, const QString &arg, const QString &var, const QString &desc)
ConfOpt &addAppOption(const QString &name, const QString &arg, const QString &var, const QString &desc)
{
ConfOpt opt;
opt.name = name;
opt.arg = arg;
opt.var = var;
opt.desc = desc;
opt.name = name;
opt.arg = arg;
opt.var = var;
opt.desc = desc;
opt.hidden = desc.isEmpty();
appopts += opt;
return appopts.last();
}

void addOption(const QString &section, const QString &name, const QString &arg, const QString &var,
const QString &desc)
ConfOpt &addOption(const QString &section, const QString &name, const QString &arg, const QString &var,
const QString &desc = QString())
{
if (section == "project")
addAppOption(name, arg, var, desc);
else
addDepOption(name, arg, var, desc);
return addAppOption(name, arg, var, desc);
return addDepOption(name, arg, var, desc);
}

QByteArray generate()
Expand Down Expand Up @@ -529,9 +533,9 @@ class ConfGen {
QList<ConfUsageOpt> optsToUsage(const QList<ConfOpt> &list) const
{
QList<ConfUsageOpt> out;
for (QList<ConfOpt>::ConstIterator it = list.begin(); it != list.end(); ++it) {
const ConfOpt &i = *it;
out += ConfUsageOpt(i.name, i.arg, i.desc);
for (auto const &opt : list) {
if (!opt.hidden)
out += ConfUsageOpt(opt.name, opt.arg, opt.desc);
}
return out;
}
Expand Down Expand Up @@ -1619,12 +1623,17 @@ int main(int argc, char **argv)
longname = dep.longname;
else
longname = dep.name;
if (!dep.required && !dep.disabled)
if (!dep.required && !dep.disabled) {
cg.addOption(dep.section, QString("disable-") + dep.name, "", QString("QC_DISABLE_") + escapeArg(dep.name),
QString("Disable use of ") + longname);
else if (dep.disabled)
cg.addOption(dep.section, QString("enable-") + dep.name, "",
QString("QC_DEFAULT_ENABLE_") + escapeArg(dep.name));
} else if (dep.disabled) {
cg.addOption(dep.section, QString("enable-") + dep.name, "", QString("QC_ENABLE_") + escapeArg(dep.name),
QString("Enable use of ") + longname);
cg.addOption(dep.section, QString("disable-") + dep.name, "",
QString("QC_DEFAULT_DISABLE_") + escapeArg(dep.name));
}

// extra dep args?
for (QList<QCModArg>::ConstIterator ait = dep.args.begin(); ait != dep.args.end(); ++ait) {
Expand Down

0 comments on commit a06a3ca

Please sign in to comment.