From 3cc49bc31cffaac1fe70f18bdf25ade312fe4ea9 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 20 Jun 2018 10:55:15 +0200 Subject: Give more help in 'No such product' error message If a user did specify a product that's not available, he most likely wants to see the product names actually available. For up to ten products, we just list the names of the products now. For a longer list of products we point to list-products command. Change-Id: I19ef16b2cf6172f02024d9dfb4c19cb81a5600a3 Reviewed-by: Leena Miettinen Reviewed-by: Christian Kandeler --- src/app/qbs/commandlinefrontend.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/app/qbs/commandlinefrontend.cpp b/src/app/qbs/commandlinefrontend.cpp index ae81265ef..d07af0d6f 100644 --- a/src/app/qbs/commandlinefrontend.cpp +++ b/src/app/qbs/commandlinefrontend.cpp @@ -346,17 +346,28 @@ CommandLineFrontend::ProductMap CommandLineFrontend::productsToUse() const const ProjectData projectData = project.projectData(); const auto products = projectData.allProducts(); for (const ProductData &product : products) { + productNames << product.name(); if (useAll || m_parser.products().contains(product.name())) { productList.push_back(product); - productNames << product.name(); } } } const auto parsedProductNames = m_parser.products(); for (const QString &productName : parsedProductNames) { - if (!productNames.contains(productName)) - throw ErrorInfo(Tr::tr("No such product '%1'.").arg(productName)); + if (!productNames.contains(productName)) { + QString msg; + if (productNames.size() <= 10) { + productNames.sort(); + const QString available = productNames.join(QLatin1String("', '")); + msg = Tr::tr("No such product '%1'. " + "Available products: '%2'").arg(productName, available); + } else { + msg = Tr::tr("No such product '%1'. Use 'list-products' to see " + "all available products.").arg(productName); + } + throw ErrorInfo(msg); + } } return products; -- cgit v1.2.3