58 {
"AppConfigLocation", QStandardPaths::AppConfigLocation,
true },
59 {
"AppDataLocation", QStandardPaths::AppDataLocation,
true },
60 {
"AppLocalDataLocation", QStandardPaths::AppLocalDataLocation,
true },
61 {
"ApplicationsLocation", QStandardPaths::ApplicationsLocation,
false },
62 {
"CacheLocation", QStandardPaths::CacheLocation,
true },
63 {
"ConfigLocation", QStandardPaths::ConfigLocation,
false },
64 {
"DesktopLocation", QStandardPaths::DesktopLocation,
false },
65 {
"DocumentsLocation", QStandardPaths::DocumentsLocation,
false },
66 {
"DownloadLocation", QStandardPaths::DownloadLocation,
false },
67 {
"FontsLocation", QStandardPaths::FontsLocation,
false },
68 {
"GenericCacheLocation", QStandardPaths::GenericCacheLocation,
false },
69 {
"GenericConfigLocation", QStandardPaths::GenericConfigLocation,
false },
70 {
"GenericDataLocation", QStandardPaths::GenericDataLocation,
false },
71 {
"GenericStateLocation", QStandardPaths::GenericStateLocation,
false },
72 {
"HomeLocation", QStandardPaths::HomeLocation,
false },
73 {
"MoviesLocation", QStandardPaths::MoviesLocation,
false },
74 {
"MusicLocation", QStandardPaths::MusicLocation,
false },
75 {
"PicturesLocation", QStandardPaths::PicturesLocation,
false },
76 {
"PublicShareLocation", QStandardPaths::PublicShareLocation,
false },
77 {
"RuntimeLocation", QStandardPaths::RuntimeLocation,
false },
78 {
"StateLocation", QStandardPaths::StateLocation,
true },
79 {
"TemplatesLocation", QStandardPaths::TemplatesLocation,
false },
80 {
"TempLocation", QStandardPaths::TempLocation,
false }
125 QString qtconfManualPath;
126 QCoreApplication app(argc, argv);
127 app.setApplicationVersion(QTPATHS_VERSION_STR);
130 const QLatin1Char pathsep(
';');
132 const QLatin1Char pathsep(
':');
135 QCommandLineParser parser;
136 parser.setApplicationDescription(QStringLiteral(
"Command line client to QStandardPaths and QLibraryInfo"));
137 parser.addPositionalArgument(QStringLiteral(
"[name]"), QStringLiteral(
"Name of file or directory"));
138 parser.addPositionalArgument(QStringLiteral(
"[properties]"), QStringLiteral(
"List of the Qt properties to query by the --qt-query argument."));
139 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
140 parser.addHelpOption();
141 parser.addVersionOption();
144 QCommandLineOption types(QStringLiteral(
"types"), QStringLiteral(
"Available location types."));
145 parser.addOption(types);
147 QCommandLineOption paths(QStringLiteral(
"paths"), QStringLiteral(
"Find paths for <type>."), QStringLiteral(
"type"));
148 parser.addOption(paths);
150 QCommandLineOption writablePath(QStringLiteral(
"writable-path"),
151 QStringLiteral(
"Find writable path for <type>."), QStringLiteral(
"type"));
152 parser.addOption(writablePath);
154 QCommandLineOption locateDir(QStringList() << QStringLiteral(
"locate-dir") << QStringLiteral(
"locate-directory"),
155 QStringLiteral(
"Locate directory [name] in <type>."), QStringLiteral(
"type"));
156 parser.addOption(locateDir);
158 QCommandLineOption locateDirs(QStringList() << QStringLiteral(
"locate-dirs") << QStringLiteral(
"locate-directories"),
159 QStringLiteral(
"Locate directories [name] in all paths for <type>."), QStringLiteral(
"type"));
160 parser.addOption(locateDirs);
162 QCommandLineOption locateFile(QStringLiteral(
"locate-file"),
163 QStringLiteral(
"Locate file [name] for <type>."), QStringLiteral(
"type"));
164 parser.addOption(locateFile);
166 QCommandLineOption locateFiles(QStringLiteral(
"locate-files"),
167 QStringLiteral(
"Locate files [name] in all paths for <type>."), QStringLiteral(
"type"));
168 parser.addOption(locateFiles);
170 QCommandLineOption findExe(QStringList() << QStringLiteral(
"find-exe") << QStringLiteral(
"find-executable"),
171 QStringLiteral(
"Find executable with [name]."));
172 parser.addOption(findExe);
174 QCommandLineOption display(QStringList() << QStringLiteral(
"display"),
175 QStringLiteral(
"Prints user readable name for <type>."), QStringLiteral(
"type"));
176 parser.addOption(display);
178 QCommandLineOption testmode(QStringList() << QStringLiteral(
"testmode") << QStringLiteral(
"test-mode"),
179 QStringLiteral(
"Use paths specific for unit testing."));
180 parser.addOption(testmode);
182 QCommandLineOption qtversion(QStringLiteral(
"qt-version"), QStringLiteral(
"Qt version."));
183 qtversion.setFlags(QCommandLineOption::HiddenFromHelp);
184 parser.addOption(qtversion);
186 QCommandLineOption installprefix(QStringLiteral(
"install-prefix"), QStringLiteral(
"Installation prefix for Qt."));
187 installprefix.setFlags(QCommandLineOption::HiddenFromHelp);
188 parser.addOption(installprefix);
190 QCommandLineOption bindir(QStringList() << QStringLiteral(
"binaries-dir") << QStringLiteral(
"binaries-directory"),
191 QStringLiteral(
"Location of Qt executables."));
192 bindir.setFlags(QCommandLineOption::HiddenFromHelp);
193 parser.addOption(bindir);
195 QCommandLineOption plugindir(QStringList() << QStringLiteral(
"plugin-dir") << QStringLiteral(
"plugin-directory"),
196 QStringLiteral(
"Location of Qt plugins."));
197 plugindir.setFlags(QCommandLineOption::HiddenFromHelp);
198 parser.addOption(plugindir);
200 QCommandLineOption query(
201 QStringList() << QStringLiteral(
"qt-query") << QStringLiteral(
"query"),
202 QStringLiteral(
"List of Qt properties. Can be used standalone or with the "
203 "--query-format and --qtconf options."));
204 parser.addOption(query);
206 QCommandLineOption queryformat(QStringLiteral(
"query-format"),
207 QStringLiteral(
"Output format for --qt-query.\nSupported formats: qmake (default), json"),
208 QStringLiteral(
"format"));
209 queryformat.setDefaultValue(
"qmake");
210 parser.addOption(queryformat);
212 QCommandLineOption qtconf(QStringLiteral(
"qtconf"),
213 QStringLiteral(
"Path to qt.conf file that will be used to override the queried Qt properties."),
214 QStringLiteral(
"path"));
215 parser.addOption(qtconf);
219 QStandardPaths::setTestModeEnabled(parser.isSet(testmode));
221#if QT_CONFIG(settings)
222 if (parser.isSet(qtconf)) {
223 qtconfManualPath = parser.value(qtconf);
224 QLibraryInfoPrivate::setQtconfManualPath(&qtconfManualPath);
229 if (parser.isSet(qtversion)) {
230 QString qtversionstring = QString::fromLatin1(QT_VERSION_STR);
231 results << qtversionstring;
234 if (parser.isSet(installprefix)) {
235 QString path = QLibraryInfo::path(QLibraryInfo::PrefixPath);
239 if (parser.isSet(bindir)) {
240 QString path = QLibraryInfo::path(QLibraryInfo::BinariesPath);
244 if (parser.isSet(plugindir)) {
245 QString path = QLibraryInfo::path(QLibraryInfo::PluginsPath);
249 if (parser.isSet(types)) {
250 QStringList typesList = ::types();
251 results << typesList.join(
'\n');
254 if (parser.isSet(display)) {
255 const StringEnum location = parseLocationOrError(parser.value(display));
256 QString text = QStandardPaths::displayName(location.enumvalue);
257 results << location.mapName(text);
260 if (parser.isSet(paths)) {
261 const StringEnum location = parseLocationOrError(parser.value(paths));
262 QStringList paths = QStandardPaths::standardLocations(location.enumvalue);
263 results << location.mapName(paths.join(pathsep));
266 if (parser.isSet(writablePath)) {
267 const StringEnum location = parseLocationOrError(parser.value(writablePath));
268 QString path = QStandardPaths::writableLocation(location.enumvalue);
269 results << location.mapName(path);
272 if (parser.isSet(findExe)) {
273 QString searchitem = searchStringOrError(&parser);
274 QString path = QStandardPaths::findExecutable(searchitem);
278 if (parser.isSet(locateDir)) {
279 const StringEnum location = parseLocationOrError(parser.value(locateDir));
280 QString searchitem = searchStringOrError(&parser);
281 QString path = QStandardPaths::locate(location.enumvalue, searchitem, QStandardPaths::LocateDirectory);
282 results << location.mapName(path);
285 if (parser.isSet(locateFile)) {
286 const StringEnum location = parseLocationOrError(parser.value(locateFile));
287 QString searchitem = searchStringOrError(&parser);
288 QString path = QStandardPaths::locate(location.enumvalue, searchitem, QStandardPaths::LocateFile);
289 results << location.mapName(path);
292 if (parser.isSet(locateDirs)) {
293 const StringEnum location = parseLocationOrError(parser.value(locateDirs));
294 QString searchitem = searchStringOrError(&parser);
295 QStringList paths = QStandardPaths::locateAll(location.enumvalue, searchitem, QStandardPaths::LocateDirectory);
296 results << location.mapName(paths.join(pathsep));
299 if (parser.isSet(locateFiles)) {
300 const StringEnum location = parseLocationOrError(parser.value(locateFiles));
301 QString searchitem = searchStringOrError(&parser);
302 QStringList paths = QStandardPaths::locateAll(location.enumvalue, searchitem, QStandardPaths::LocateFile);
303 results << location.mapName(paths.join(pathsep));
306#if !QT_CONFIG(settings)
307 if (parser.isSet(query) || parser.isSet(qtconf) || parser.isSet(queryformat)) {
308 error(QStringLiteral(
"--qt-query, --qtconf and --query-format options are not supported. The 'settings' feature is missing."));
311 if (parser.isSet(query)) {
312 if (!results.isEmpty()) {
313 QString errorMessage = QStringLiteral(
"Several options given, only one is supported at a time.");
317 PropertyPrinter printer;
318 if (parser.isSet(queryformat)) {
319 QString formatValue = parser.value(queryformat);
320 if (formatValue ==
"json") {
321 printer = jsonPropertyPrinter;
322 }
else if (formatValue !=
"qmake") {
323 QString errorMessage = QStringLiteral(
"Invalid output format %1. Supported formats: qmake, json").arg(formatValue);
328 QStringList optionProperties = parser.positionalArguments();
331 return prop.queryProperty(optionProperties, printer);
333 return prop.queryProperty(optionProperties);
334 }
else if (parser.isSet(queryformat)) {
335 error(QStringLiteral(
"--query-format is set, but --qt-query is not requested."));
339 if (results.isEmpty()) {
341 }
else if (results.size() == 1) {
342 const QString &item = results.constFirst();
347 QString errorMessage = QStringLiteral(
"Several options given, only one is supported at a time.");