diff options
author | Christian Kandeler <christian.kandeler@digia.com> | 2012-11-01 17:52:06 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@digia.com> | 2012-11-02 17:43:24 +0100 |
commit | b17a51ac6df09ffab5643b9609ce542dd3bb81cf (patch) | |
tree | 2110d83e40952bf4361e2507bae486c73b6aa1ba /src/app/shared | |
parent | 2477c391134f1e49b9a41c18f2765585d4818622 (diff) |
Add a progress indicator for the command-line client.
This is considered useful especially for larger projects.
Along the way, fix some progress observer problems uncovered
by this addition.
Change-Id: I520a50d74ca10a1a125b0c11318613c23ffc17d2
Task-number: QBS-156
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'src/app/shared')
-rw-r--r-- | src/app/shared/commandlineparser.cpp | 24 | ||||
-rw-r--r-- | src/app/shared/commandlineparser.h | 2 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/app/shared/commandlineparser.cpp b/src/app/shared/commandlineparser.cpp index 37faa9d8e..3d8c88a17 100644 --- a/src/app/shared/commandlineparser.cpp +++ b/src/app/shared/commandlineparser.cpp @@ -40,7 +40,9 @@ #include <QTextStream> #include <QThread> -#include <cstdio> +#ifdef Q_OS_UNIX +#include <unistd.h> +#endif namespace qbs { @@ -80,6 +82,7 @@ CommandLineParser::CommandLineParser() m_settings = Settings::create(); } +// TODO: Symbolic constants for all option and command names. void CommandLineParser::printHelp() const { QTextStream stream(m_help ? stdout : stderr); @@ -112,11 +115,14 @@ void CommandLineParser::printHelp() const " .............. Assume these and only these files have changed.\n" " --products name[,name...]\n" " .............. Build only the specified products.\n" +#ifdef Q_OS_UNIX + " --show-progress . Show a progress bar. Implies --log-level=%3.\n" +#endif " --log-level level\n" " .............. Use the specified log level. Possible values are \"%1\".\n" " The default is \"%2\".\n") .arg(allLogLevelStrings().join(QLatin1String("\", \"")), - logLevelToString(Logger::defaultLevel())); + logLevelToString(Logger::defaultLevel()), logLevelToString(LoggerMinLevel)); } /** @@ -145,6 +151,7 @@ void CommandLineParser::doParse() if (m_buildOptions.maxJobCount <= 0) m_buildOptions.maxJobCount = QThread::idealThreadCount(); m_help = false; + m_showProgress = false; m_logLevel = Logger::defaultLevel(); while (!m_commandLine.isEmpty()) { @@ -159,6 +166,11 @@ void CommandLineParser::doParse() parseArgument(arg); } + if (m_showProgress && m_logLevel != LoggerMinLevel) { + qbsInfo() << tr("Setting log level to \"%1\", because option \"--show-progress\"" + " has been given.").arg(logLevelToString(LoggerMinLevel)); + m_logLevel = LoggerMinLevel; + } if (m_logLevel < LoggerMinLevel) { qbsWarning() << tr("Cannot decrease log level as much as specified; using \"%1\".") .arg(logLevelToString(LoggerMinLevel)); @@ -212,6 +224,14 @@ void CommandLineParser::parseLongOption(const QString &option) } else if (optionName == QLatin1String("products") && (m_command == BuildCommand || m_command == CleanCommand || m_command == PropertiesCommand)) { m_buildOptions.selectedProductNames = getOptionArgumentAsList(option); +#ifdef Q_OS_UNIX + } else if (optionName == QLatin1String("show-progress")) { + if (isatty(STDOUT_FILENO)) + m_showProgress = true; + else + qbsWarning() << tr("Ignoring option \"--show-progress\", because standard output is " + "not connected to a terminal."); +#endif } else if (optionName == QLatin1String("log-level")) { m_logLevel = logLevelFromString(getOptionArgument(option)); } else { diff --git a/src/app/shared/commandlineparser.h b/src/app/shared/commandlineparser.h index bc5a8209b..95cbc56d4 100644 --- a/src/app/shared/commandlineparser.h +++ b/src/app/shared/commandlineparser.h @@ -64,6 +64,7 @@ public: const QStringList &runArgs() const { return m_runArgs; } bool isHelpSet() const { return m_help; } QList<QVariantMap> buildConfigurations() const; + bool showProgress() const { return m_showProgress; } private: void doParse(); @@ -88,6 +89,7 @@ private: BuildOptions m_buildOptions; bool m_help; int m_logLevel; + bool m_showProgress; }; } #endif // OPTIONS_H |