Merge pull request #1262 from ispyisail/fix/cli-common-elements-dir

Fix --common-elements-dir being ignored by --run and the export
This commit is contained in:
Laurent Trinques
2026-10-02 23:06:15 +02:00
committed by GitHub
3 changed files with 73 additions and 34 deletions
+26 -2
View File
@@ -93,6 +93,30 @@ void qetLogMessageHandler(QtMsgType type,
\~French paramètres
\~ @return exit code
*/
/**
@brief headlessArguments
For the headless export and --run, which return before QETApp parses
the command line: apply the folder options (--common-elements-dir= and
the others QETArguments knows) and return the arguments without them,
so they are not read as the project or output path (issue #1178).
*/
static QStringList headlessArguments(const QStringList &args)
{
QETApp::applyDirectoryArguments(QETArguments(args.mid(1)));
static const QStringList folder_options {
QStringLiteral("--common-elements-dir="), QStringLiteral("--common-tbt-dir="),
QStringLiteral("--config-dir="), QStringLiteral("--data-dir="),
QStringLiteral("--lang-dir=")};
QStringList kept;
for (const QString &arg : args) {
bool folder = false;
for (const QString &option : folder_options)
folder = folder || arg.startsWith(option);
if (!folder) kept << arg;
}
return kept;
}
int main(int argc, char **argv)
{
// before creating Application:
@@ -165,7 +189,7 @@ int main(int argc, char **argv)
// QETProject::readProjectXml(), and with nobody able to dismiss it
// QDialog::exec() would spin its event loop forever.
QET::QetMessageBox::setNonInteractive(true);
return CLIExport::run(export_app.arguments());
return CLIExport::run(headlessArguments(export_app.arguments()));
}
#ifdef QET_HAS_SCRIPTING
// Headless scripting: --run <script.js> <project.qet> (bugtracker
@@ -175,7 +199,7 @@ int main(int argc, char **argv)
QApplication script_app(argc, argv);
QETProject::setBackupEnabled(false);
QET::QetMessageBox::setNonInteractive(true);
return QetScripting::run(script_app.arguments());
return QetScripting::run(headlessArguments(script_app.arguments()));
}
#endif
}
+46 -32
View File
@@ -658,6 +658,15 @@ QString QETApp::commonElementsDir()
{
m_common_element_dir_is_set = true;
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
//A folder given on the command line, for this run, comes
//before the one saved in the settings.
if (m_overrided_common_elements_dir != QString()) {
m_common_element_dir = m_overrided_common_elements_dir;
return(m_common_element_dir);
}
#endif
//Check if user define a custom path
//for the common collection
QSettings settings;
@@ -674,12 +683,6 @@ QString QETApp::commonElementsDir()
}
}
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
if (m_overrided_common_elements_dir != QString()) {
m_common_element_dir = m_overrided_common_elements_dir;
return(m_common_element_dir);
}
#endif
#ifndef QET_COMMON_COLLECTION_PATH
/* in the absence of a compilation option,
* we use the elements folder, located next to the executable binary
@@ -2389,6 +2392,42 @@ QList<QWidget *> QETApp::floatingToolbarsAndDocksForMainWindow(
}
/**
@brief QETApp::applyDirectoryArguments
Apply the folder options (--common-elements-dir=, --common-tbt-dir=,
--config-dir=, --data-dir=, --lang-dir=) of @p arguments. Static, so
the headless export and --run in main() can apply them too: they
return before a QETApp exists.
*/
void QETApp::applyDirectoryArguments(const QETArguments &arguments)
{
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
if (arguments.commonElementsDirSpecified()) {
overrideCommonElementsDir(arguments.commonElementsDir());
}
#endif
#ifdef QET_ALLOW_OVERRIDE_CTBTD_OPTION
if (arguments.commonTitleBlockTemplatesDirSpecified()) {
overrideCommonTitleBlockTemplatesDir(
arguments.commonTitleBlockTemplatesDir());
}
#endif
#ifdef QET_ALLOW_OVERRIDE_CD_OPTION
if (arguments.configDirSpecified()) {
overrideConfigDir(arguments.configDir());
}
#endif
#ifdef QET_ALLOW_OVERRIDE_DD_OPTION
if (arguments.dataDirSpecified()) {
overrideDataDir(arguments.dataDir());
}
#endif
if (arguments.langDirSpecified()) {
overrideLangDir(arguments.langDir());
}
}
/**
@brief QETApp::parseArguments
Parse the following arguments:
@@ -2430,32 +2469,7 @@ void QETApp::parseArguments()
// analyze the arguments
// analyse les arguments
qet_arguments_ = QETArguments(arguments_list);
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
if (qet_arguments_.commonElementsDirSpecified()) {
overrideCommonElementsDir(qet_arguments_.commonElementsDir());
}
#endif
#ifdef QET_ALLOW_OVERRIDE_CTBTD_OPTION
if (qet_arguments_.commonTitleBlockTemplatesDirSpecified()) {
overrideCommonTitleBlockTemplatesDir(
qet_arguments_.commonTitleBlockTemplatesDir());
}
#endif
#ifdef QET_ALLOW_OVERRIDE_CD_OPTION
if (qet_arguments_.configDirSpecified()) {
overrideConfigDir(qet_arguments_.configDir());
}
#endif
#ifdef QET_ALLOW_OVERRIDE_DD_OPTION
if (qet_arguments_.dataDirSpecified()) {
overrideDataDir(qet_arguments_.dataDir());
}
#endif
if (qet_arguments_.langDirSpecified()) {
overrideLangDir(qet_arguments_.langDir());
}
applyDirectoryArguments(qet_arguments_);
if (qet_arguments_.printLicenseRequested()) {
printLicense();
+1
View File
@@ -115,6 +115,7 @@ class QETApp : public QObject
static QStringList handledFiles(const QList<QUrl> &);
static RecentFiles *projectsRecentFiles();
static RecentFiles *elementsRecentFiles();
static void applyDirectoryArguments(const QETArguments &);
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
public: