qdbusxml2cpp: Fail if -c option is used with multiple interfaces

Exit with an error code when -c option is specified by the command
is not processing a single interface. Mention this in the option
description.

Fixes: QTBUG-36405
Change-Id: I7ea217c780d37332278c634f030d20040b7459e6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ievgenii Meshcheriakov 2023-05-26 14:36:36 +02:00
parent 6f6bd2c4dc
commit 1ee7aa741a

View File

@ -1087,7 +1087,9 @@ int main(int argc, char **argv)
parser.addOption(adapterCodeOption); parser.addOption(adapterCodeOption);
QCommandLineOption classNameOption(QStringList{u"c"_s, u"classname"_s}, QCommandLineOption classNameOption(QStringList{u"c"_s, u"classname"_s},
u"Use <classname> as the class name for the generated classes"_s, u"classname"_s); u"Use <classname> as the class name for the generated classes. "
u"This option can only be used when processing a single interface."_s,
u"classname"_s);
parser.addOption(classNameOption); parser.addOption(classNameOption);
QCommandLineOption addIncludeOption(QStringList{u"i"_s, u"include"_s}, QCommandLineOption addIncludeOption(QStringList{u"i"_s, u"include"_s},
@ -1147,6 +1149,11 @@ int main(int argc, char **argv)
QDBusIntrospection::Interfaces interfaces = readInput(); QDBusIntrospection::Interfaces interfaces = readInput();
cleanInterfaces(interfaces); cleanInterfaces(interfaces);
if (!globalClassName.isEmpty() && interfaces.count() != 1) {
qCritical("Option -c/--classname can only be used with a single interface.\n");
return 1;
}
QStringList args = app.arguments(); QStringList args = app.arguments();
args.removeFirst(); args.removeFirst();
commandLine = PROGRAMNAME " "_L1 + args.join(u' '); commandLine = PROGRAMNAME " "_L1 + args.join(u' ');