-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmdlineargs: Error handling and translation #4170
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e951cd5
cmdlineargs: Added a second parser path for user feedback ...
daschuer f6611d7
Add PaseMode enum to get around a bool function parameter
daschuer ffcb69f
Improve commenets
daschuer 456c542
rename m_hasUserFeedback in m_parseForUserFeedbackRequired
daschuer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include "config.h" | ||
#include "defs_urls.h" | ||
#include "sources/soundsourceproxy.h" | ||
#include "util/assert.h" | ||
|
||
CmdlineArgs::CmdlineArgs() | ||
: m_startInFullscreen(false), // Initialize vars | ||
|
@@ -24,6 +25,7 @@ CmdlineArgs::CmdlineArgs() | |
m_debugAssertBreak(false), | ||
m_settingsPathSet(false), | ||
m_useColors(false), | ||
m_hasUserFeedback(false), | ||
m_logLevel(mixxx::kLogLevelDefault), | ||
m_logFlushLevel(mixxx::kLogFlushLevelDefault), | ||
// We are not ready to switch to XDG folders under Linux, so keeping $HOME/.mixxx as preferences folder. see lp:1463273 | ||
|
@@ -73,39 +75,54 @@ bool CmdlineArgs::parse(int argc, char** argv) { | |
for (int a = 0; a < argc; ++a) { | ||
arguments << QString::fromLocal8Bit(argv[a]); | ||
} | ||
return parse(arguments, false); | ||
} | ||
|
||
void CmdlineArgs::parseForUserFeedback() { | ||
DEBUG_ASSERT(QCoreApplication::instance()); | ||
if (!m_hasUserFeedback) { | ||
return; | ||
} | ||
parse(QCoreApplication::arguments(), true); | ||
} | ||
|
||
bool CmdlineArgs::parse(const QStringList& arguments, bool forUserFeedback) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add |
||
QCommandLineParser parser; | ||
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); | ||
|
||
parser.setApplicationDescription( | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Mixxx is an open source DJ software. For more " | ||
"information, see: ") + | ||
MIXXX_MANUAL_COMMANDLINEOPTIONS_URL); | ||
|
||
if (forUserFeedback) { | ||
parser.setApplicationDescription( | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Mixxx is an open source DJ software. For more " | ||
"information, see: ") + | ||
MIXXX_MANUAL_COMMANDLINEOPTIONS_URL); | ||
} | ||
// add options | ||
const QCommandLineOption fullScreen( | ||
QStringList({QStringLiteral("f"), QStringLiteral("full-screen")}), | ||
QCoreApplication::translate( | ||
"CmdlineArgs", "Starts Mixxx in full-screen mode")); | ||
forUserFeedback ? QCoreApplication::translate( | ||
"CmdlineArgs", "Starts Mixxx in full-screen mode") | ||
: QString()); | ||
QCommandLineOption fullScreenDeprecated(QStringLiteral("fullScreen")); | ||
fullScreenDeprecated.setFlags(QCommandLineOption::HiddenFromHelp); | ||
parser.addOption(fullScreen); | ||
parser.addOption(fullScreenDeprecated); | ||
|
||
const QCommandLineOption locale(QStringLiteral("locale"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Use a custom locale for loading translations. (e.g " | ||
"'fr')"), | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Use a custom locale for loading translations. (e.g " | ||
"'fr')") | ||
: QString(), | ||
QStringLiteral("locale")); | ||
parser.addOption(locale); | ||
|
||
// An option with a value | ||
const QCommandLineOption settingsPath(QStringLiteral("settings-path"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Top-level directory where Mixxx should look for settings. " | ||
"Default is:") + | ||
getSettingsPath(), | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Top-level directory where Mixxx should look for settings. " | ||
"Default is:") + | ||
getSettingsPath() | ||
: QString(), | ||
QStringLiteral("path")); | ||
QCommandLineOption settingsPathDeprecated( | ||
QStringLiteral("settingsPath")); | ||
|
@@ -115,10 +132,11 @@ bool CmdlineArgs::parse(int argc, char** argv) { | |
parser.addOption(settingsPathDeprecated); | ||
|
||
QCommandLineOption resourcePath(QStringLiteral("resource-path"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Top-level directory where Mixxx should look for its " | ||
"resource files such as MIDI mappings, overriding the " | ||
"default installation location."), | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Top-level directory where Mixxx should look for its " | ||
"resource files such as MIDI mappings, overriding the " | ||
"default installation location.") | ||
: QString(), | ||
QStringLiteral("path")); | ||
QCommandLineOption resourcePathDeprecated( | ||
QStringLiteral("resourcePath")); | ||
|
@@ -128,8 +146,9 @@ bool CmdlineArgs::parse(int argc, char** argv) { | |
parser.addOption(resourcePathDeprecated); | ||
|
||
const QCommandLineOption timelinePath(QStringLiteral("timeline-path"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Path the debug statistics time line is written to"), | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Path the debug statistics time line is written to") | ||
: QString(), | ||
QStringLiteral("path")); | ||
QCommandLineOption timelinePathDeprecated( | ||
QStringLiteral("timelinePath"), timelinePath.description()); | ||
|
@@ -139,9 +158,10 @@ bool CmdlineArgs::parse(int argc, char** argv) { | |
parser.addOption(timelinePathDeprecated); | ||
|
||
const QCommandLineOption controllerDebug(QStringLiteral("controller-debug"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Causes Mixxx to display/log all of the controller data it " | ||
"receives and script functions it loads")); | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Causes Mixxx to display/log all of the controller data it " | ||
"receives and script functions it loads") | ||
: QString()); | ||
QCommandLineOption controllerDebugDeprecated( | ||
QStringList({QStringLiteral("controllerDebug"), | ||
QStringLiteral("midiDebug")})); | ||
|
@@ -150,36 +170,40 @@ bool CmdlineArgs::parse(int argc, char** argv) { | |
parser.addOption(controllerDebugDeprecated); | ||
|
||
const QCommandLineOption developer(QStringLiteral("developer"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Enables developer-mode. Includes extra log info, stats on " | ||
"performance, and a Developer tools menu.")); | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Enables developer-mode. Includes extra log info, stats on " | ||
"performance, and a Developer tools menu.") | ||
: QString()); | ||
parser.addOption(developer); | ||
|
||
const QCommandLineOption safeMode(QStringLiteral("safe-mode"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Enables safe-mode. Disables OpenGL waveforms, and " | ||
"spinning vinyl widgets. Try this option if Mixxx is " | ||
"crashing on startup.")); | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Enables safe-mode. Disables OpenGL waveforms, and " | ||
"spinning vinyl widgets. Try this option if Mixxx is " | ||
"crashing on startup.") | ||
: QString()); | ||
QCommandLineOption safeModeDeprecated(QStringLiteral("safeMode"), safeMode.description()); | ||
safeModeDeprecated.setFlags(QCommandLineOption::HiddenFromHelp); | ||
parser.addOption(safeMode); | ||
parser.addOption(safeModeDeprecated); | ||
|
||
const QCommandLineOption color(QStringLiteral("color"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"[auto|always|never] Use colors on the console output."), | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"[auto|always|never] Use colors on the console output.") | ||
: QString(), | ||
QStringLiteral("color"), | ||
QStringLiteral("auto")); | ||
parser.addOption(color); | ||
|
||
const QCommandLineOption logLevel(QStringLiteral("log-level"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Sets the verbosity of command line logging.\n" | ||
"critical - Critical/Fatal only\n" | ||
"warning - Above + Warnings\n" | ||
"info - Above + Informational messages\n" | ||
"debug - Above + Debug/Developer messages\n" | ||
"trace - Above + Profiling messages"), | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Sets the verbosity of command line logging.\n" | ||
"critical - Critical/Fatal only\n" | ||
"warning - Above + Warnings\n" | ||
"info - Above + Informational messages\n" | ||
"debug - Above + Debug/Developer messages\n" | ||
"trace - Above + Profiling messages") | ||
: QString(), | ||
QStringLiteral("level")); | ||
QCommandLineOption logLevelDeprecated(QStringLiteral("logLevel"), logLevel.description()); | ||
logLevelDeprecated.setFlags(QCommandLineOption::HiddenFromHelp); | ||
|
@@ -188,10 +212,11 @@ bool CmdlineArgs::parse(int argc, char** argv) { | |
parser.addOption(logLevelDeprecated); | ||
|
||
const QCommandLineOption logFlushLevel(QStringLiteral("log-flush-level"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Sets the the logging level at which the log buffer is " | ||
"flushed to mixxx.log. <level> is one of the values defined " | ||
"at --log-level above."), | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Sets the the logging level at which the log buffer is " | ||
"flushed to mixxx.log. <level> is one of the values defined " | ||
"at --log-level above.") | ||
: QString(), | ||
QStringLiteral("level")); | ||
QCommandLineOption logFlushLevelDeprecated( | ||
QStringLiteral("logFlushLevel"), logLevel.description()); | ||
|
@@ -201,9 +226,10 @@ bool CmdlineArgs::parse(int argc, char** argv) { | |
parser.addOption(logFlushLevelDeprecated); | ||
|
||
QCommandLineOption debugAssertBreak(QStringLiteral("debug-assert-break"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Breaks (SIGINT) Mixxx, if a DEBUG_ASSERT evaluates to " | ||
"false. Under a debugger you can continue afterwards.")); | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Breaks (SIGINT) Mixxx, if a DEBUG_ASSERT evaluates to " | ||
"false. Under a debugger you can continue afterwards.") | ||
: QString()); | ||
QCommandLineOption debugAssertBreakDeprecated( | ||
QStringLiteral("debugAssertBreak"), debugAssertBreak.description()); | ||
debugAssertBreakDeprecated.setFlags(QCommandLineOption::HiddenFromHelp); | ||
|
@@ -214,29 +240,33 @@ bool CmdlineArgs::parse(int argc, char** argv) { | |
const QCommandLineOption versionOption = parser.addVersionOption(); | ||
|
||
parser.addPositionalArgument(QStringLiteral("file"), | ||
QCoreApplication::translate("CmdlineArgs", | ||
"Load the specified music file(s) at start-up. Each file " | ||
"you specify will be loaded into the next virtual deck.")); | ||
forUserFeedback ? QCoreApplication::translate("CmdlineArgs", | ||
"Load the specified music file(s) at start-up. Each file " | ||
"you specify will be loaded into the next virtual deck.") | ||
: QString()); | ||
|
||
if (forUserFeedback) { | ||
// We know form the first path, that there will be likely an error message, check again. | ||
// This is not the case if the user uses a Qt internal option that is unknown | ||
// in the first path | ||
puts(""); // Add a blank line to make the parser output more visible | ||
// This call does not return and calls exit() in case of help or an parser error | ||
parser.process(arguments); | ||
return true; | ||
} | ||
|
||
// process all arguments | ||
if (!parser.parse(arguments)) { | ||
qWarning() << parser.errorText(); | ||
m_hasUserFeedback = true; | ||
} | ||
|
||
if (parser.isSet(helpOption) | ||
if (parser.isSet(versionOption) || | ||
parser.isSet(helpOption) | ||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) | ||
|| parser.isSet(QStringLiteral("help-all")) | ||
#endif | ||
) { | ||
// we need to call process here with an initialized QCoreApplication | ||
// otherwise there is no way to print the help-all information | ||
QCoreApplication coreApp(argc, argv); | ||
parser.process(arguments); | ||
return false; | ||
} | ||
if (parser.isSet(versionOption)) { | ||
parser.showVersion(); | ||
return false; | ||
m_hasUserFeedback = true; | ||
} | ||
|
||
m_startInFullscreen = parser.isSet(fullScreen) || parser.isSet(fullScreenDeprecated); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition seems to be wrong or I misunderstand the purpose/naming of the boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need only execute the second run when the first run has produced user feedback, otherwise we can skip the second run. I am happy to rename the variable if you have a suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_requiresUserFeedback
orm_needsUserFeedback
? German: "erfordert"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be read as if we require feedback from the user.
How about m_parseForUserFeedbackRequired?