Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "commandlineparser.h"
23 :
24 : #include <QDir>
25 :
26 : #include "global/io/dir.h"
27 : #include "global/internal/baseapplication.h"
28 :
29 : #include "app_config.h"
30 :
31 : #include "log.h"
32 :
33 : using namespace muse;
34 : using namespace mu::app;
35 :
36 0 : static QStringList prepareArguments(int argc, char** argv)
37 : {
38 0 : QStringList args;
39 :
40 0 : for (int i = 0; i < argc; ++i) {
41 0 : QString arg = QString::fromUtf8(argv[i]);
42 :
43 : #ifndef NDEBUG
44 0 : if (arg.startsWith("-qmljsdebugger")) {
45 0 : continue;
46 : }
47 : #endif
48 :
49 0 : args << arg;
50 0 : }
51 :
52 0 : return args;
53 0 : }
54 :
55 : template<typename ... Args>
56 0 : QCommandLineOption internalCommandLineOption(Args&& ... args)
57 : {
58 0 : QCommandLineOption option(std::forward<Args>(args)...);
59 0 : option.setFlags(QCommandLineOption::HiddenFromHelp);
60 0 : return option;
61 0 : }
62 :
63 0 : void CommandLineParser::init()
64 : {
65 : // Common
66 0 : m_parser.addHelpOption(); // -?, -h, --help
67 0 : m_parser.addVersionOption(); // -v, --version
68 :
69 0 : m_parser.addPositionalArgument("scorefiles", "The files to open", "[scorefile...]");
70 :
71 0 : m_parser.addOption(QCommandLineOption("long-version", "Print detailed version information"));
72 0 : m_parser.addOption(QCommandLineOption({ "d", "debug" }, "Debug mode"));
73 :
74 0 : m_parser.addOption(QCommandLineOption({ "D", "monitor-resolution" }, "Specify monitor resolution", "DPI"));
75 0 : m_parser.addOption(QCommandLineOption({ "T", "trim-image" },
76 : "Use with '-o <file>.png' and '-o <file.svg>'. Trim exported image with specified margin (in pixels)",
77 0 : "margin"));
78 :
79 0 : m_parser.addOption(QCommandLineOption({ "b", "bitrate" }, "Use with '-o <file>.mp3', sets bitrate, in kbps", "bitrate"));
80 :
81 0 : m_parser.addOption(QCommandLineOption("template-mode", "Save template mode, no page size")); // and no platform and creationDate tags
82 0 : m_parser.addOption(QCommandLineOption({ "t", "test-mode" }, "Set test mode flag for all files")); // this includes --template-mode
83 :
84 0 : m_parser.addOption(QCommandLineOption("session-type", "Startup with given session type", "type")); // see StartupScenario::sessionTypeTromString
85 :
86 0 : m_parser.addOption(QCommandLineOption("unroll-repeats", "Unroll repeats"));
87 :
88 : // Converter mode
89 0 : m_parser.addOption(QCommandLineOption({ "r", "image-resolution" }, "Set output resolution for image export", "DPI"));
90 0 : m_parser.addOption(QCommandLineOption({ "o", "export-to" }, "Export to 'file'. Format depends on file's extension", "file"));
91 0 : m_parser.addOption(QCommandLineOption({ "j", "job" }, "Process a conversion job", "file"));
92 0 : m_parser.addOption(QCommandLineOption("extension", "Use extension to process a conversion job", "uri"));
93 :
94 0 : m_parser.addOption(QCommandLineOption({ "F", "factory-settings" }, "Use factory settings"));
95 0 : m_parser.addOption(QCommandLineOption({ "R", "revert-settings" }, "Revert to factory settings, but keep default preferences"));
96 0 : m_parser.addOption(QCommandLineOption({ "M", "midi-operations" }, "Specify MIDI import operations file", "file"));
97 0 : m_parser.addOption(QCommandLineOption({ "P", "export-score-parts" }, "Use with '-o <file>.pdf', export score and parts"));
98 0 : m_parser.addOption(QCommandLineOption({ "f", "force" },
99 0 : "Use with '-o <file>', ignore warnings reg. score being corrupted or from wrong version"));
100 :
101 0 : m_parser.addOption(QCommandLineOption("score-media",
102 0 : "Export all media (excepting mp3) for a given score in a single JSON file and print it to stdout"));
103 0 : m_parser.addOption(QCommandLineOption("highlight-config", "Set highlight to svg, generated from a given score", "highlight-config"));
104 0 : m_parser.addOption(QCommandLineOption("score-meta", "Export score metadata to JSON document and print it to stdout"));
105 0 : m_parser.addOption(QCommandLineOption("score-parts", "Generate parts data for the given score and save them to separate mscz files"));
106 0 : m_parser.addOption(QCommandLineOption("score-parts-pdf",
107 0 : "Generate parts data for the given score and export the data to a single JSON file, print it to stdout"));
108 0 : m_parser.addOption(QCommandLineOption("score-transpose",
109 : "Transpose the given score and export the data to a single JSON file, print it to stdout",
110 0 : "options"));
111 0 : m_parser.addOption(QCommandLineOption("score-elements",
112 0 : "Scan the given score and export elements to a single JSON file, print it to stdout"));
113 0 : m_parser.addOption(QCommandLineOption("source-update", "Update the source in the given score"));
114 :
115 0 : m_parser.addOption(QCommandLineOption({ "S", "style" }, "Load style file", "style"));
116 :
117 0 : m_parser.addOption(QCommandLineOption("sound-profile",
118 : "Use with '-o <file>.mp3' or with '-j <file>', override the sound profile in the given score(s). "
119 0 : "Possible values: \"MuseScore Basic\", \"MuseSounds\"", "sound-profile"));
120 :
121 0 : m_parser.addOption(QCommandLineOption("tracks-diff",
122 : "Use with -o <file>.mp3, write a diff of tracks before and after applying the sound profile. "
123 : "The report contains two lists: oldTracks and newTracks",
124 0 : "tracks-diff"));
125 :
126 0 : m_parser.addOption(QCommandLineOption("transpose",
127 : "Transpose the given score before executing the '-o' options",
128 0 : "options"));
129 :
130 0 : m_parser.addOption(QCommandLineOption("page",
131 : "Use with '-o <file>', export only the specified page. "
132 : "Supported output formats: SVG, PNG, PDF, MSCZ",
133 0 : "options"));
134 :
135 0 : m_parser.addOption(QCommandLineOption("region",
136 : "Use with '-o <file>', export only the specified region to a separate mscz file. ",
137 0 : "options"));
138 :
139 : // MusicXML
140 0 : m_parser.addOption(QCommandLineOption("musicxml-use-default-font",
141 0 : "Apply default typeface (Edwin) to imported scores"));
142 0 : m_parser.addOption(QCommandLineOption("musicxml-infer-text-type",
143 0 : "Infer text type based on content where possible"));
144 :
145 : // Video export
146 : #ifdef MUE_BUILD_IMPEXP_VIDEOEXPORT_MODULE
147 0 : m_parser.addOption(QCommandLineOption("score-video", "Generate video for the given score and export it to file"));
148 : // not implemented
149 : // m_parser.addOption(QCommandLineOption("view-mode",
150 : // "View mode [paged-float, paged-original, paged-float-height, pano, auto]. Auto (default) will choose the best mode according to number of instruments etc... Will show piano for piano score only",
151 : // "auto"));
152 : // not implemented
153 : // m_parser.addOption(QCommandLineOption("piano", "Show Piano, works only if one part and not auto or float modes"));
154 : // m_parser.addOption(QCommandLineOption("piano-position", "Show Piano top or bottom. Default bottom", "bottom"));
155 0 : m_parser.addOption(QCommandLineOption("resolution", "Resolution [2160p, 1440p, 1080p, 720p, 480p, 360p]", "1080p"));
156 0 : m_parser.addOption(QCommandLineOption("fps", "Frame per second [60, 30, 24]", "24"));
157 0 : m_parser.addOption(QCommandLineOption("ls", "Pause before playback in seconds (3.0)", "3.0"));
158 0 : m_parser.addOption(QCommandLineOption("ts", "Pause before end of video in seconds (3.0)", "3.0"));
159 0 : m_parser.addOption(QCommandLineOption("no-audio", "Export video without audio"));
160 : #endif
161 :
162 0 : m_parser.addOption(QCommandLineOption("gp-linked", "create tabulature linked staves for guitar pro"));
163 0 : m_parser.addOption(QCommandLineOption("gp-experimental", "experimental features for guitar pro import"));
164 :
165 : //! NOTE Currently only implemented `full` mode
166 0 : m_parser.addOption(QCommandLineOption("migration", "Whether to do migration with given mode, `full` - full migration", "mode"));
167 :
168 : // Diagnostic
169 0 : m_parser.addOption(QCommandLineOption("diagnostic-output", "Diagnostic output", "output"));
170 0 : m_parser.addOption(QCommandLineOption("diagnostic-gen-drawdata", "Generate engraving draw data", "scores-dir"));
171 0 : m_parser.addOption(QCommandLineOption("diagnostic-com-drawdata", "Compare engraving draw data"));
172 0 : m_parser.addOption(QCommandLineOption("diagnostic-drawdata-to-png", "Convert draw data to png", "file"));
173 0 : m_parser.addOption(QCommandLineOption("diagnostic-drawdiff-to-png", "Convert draw diff to png"));
174 :
175 : // Testflow
176 0 : m_parser.addOption(QCommandLineOption("test-case", "Run test case by name or file", "nameOrFile"));
177 0 : m_parser.addOption(QCommandLineOption("test-case-context", "Set test case context by name or file", "nameOrFile"));
178 0 : m_parser.addOption(QCommandLineOption("test-case-context-value", "Set test case context value", "value"));
179 0 : m_parser.addOption(QCommandLineOption("test-case-func", "Call test case function", "name"));
180 0 : m_parser.addOption(QCommandLineOption("test-case-func-args", "Call test case function args", "args"));
181 :
182 : // Audio plugins
183 0 : m_parser.addOption(QCommandLineOption("register-audio-plugin",
184 0 : "Check an audio plugin for compatibility with the application and register it", "path"));
185 0 : m_parser.addOption(QCommandLineOption("register-audio-plugin-out", "Write audio plugin registration result to file", "path"));
186 :
187 : // Internal
188 0 : m_parser.addOption(internalCommandLineOption("score-display-name-override",
189 : "Display name to be shown in splash screen for the score that is being opened", "name"));
190 0 : }
191 :
192 0 : void CommandLineParser::parse(int argc, char** argv)
193 : {
194 0 : m_options = std::make_shared<MuseScoreCmdOptions>();
195 :
196 0 : QStringList args = prepareArguments(argc, argv);
197 0 : m_parser.parse(args);
198 :
199 0 : auto floatValue = [this](const QString& name) -> std::optional<float> {
200 0 : bool ok = true;
201 0 : float val = m_parser.value(name).toFloat(&ok);
202 0 : if (ok) {
203 0 : return val;
204 : }
205 0 : return std::nullopt;
206 0 : };
207 :
208 0 : auto doubleValue = [this](const QString& name) -> std::optional<double> {
209 0 : bool ok = true;
210 0 : double val = m_parser.value(name).toDouble(&ok);
211 0 : if (ok) {
212 0 : return val;
213 : }
214 0 : return std::nullopt;
215 0 : };
216 :
217 0 : auto intValue = [this](const QString& name) -> std::optional<int> {
218 0 : bool ok = true;
219 0 : int val = m_parser.value(name).toInt(&ok);
220 0 : if (ok) {
221 0 : return val;
222 : }
223 0 : return std::nullopt;
224 0 : };
225 :
226 0 : auto fromUserInputPath = [](const QString& path) -> QString {
227 0 : return io::Dir::fromNativeSeparators(path).toQString();
228 : };
229 :
230 0 : QStringList scorefiles;
231 0 : for (const QString& arg : m_parser.positionalArguments()) {
232 0 : scorefiles << fromUserInputPath(arg);
233 0 : }
234 :
235 0 : auto firstScoreFile = [](const QStringList& scorefiles) -> QString {
236 0 : if (scorefiles.size() < 1) {
237 0 : LOGE() << "Option: -o no input file specified";
238 0 : return QString();
239 0 : } else if (scorefiles.size() > 1) {
240 0 : LOGW() << "Option: -o multiple input files specified; processing only the first one";
241 : }
242 0 : return scorefiles.front();
243 : };
244 :
245 0 : if (m_parser.isSet("long-version")) {
246 0 : printLongVersion();
247 0 : exit(EXIT_SUCCESS);
248 : }
249 :
250 0 : if (m_parser.isSet("d")) {
251 0 : m_options->global.loggerLevel = logger::Level::Debug;
252 : }
253 :
254 0 : if (m_parser.isSet("D")) {
255 0 : std::optional<double> val = doubleValue("D");
256 0 : if (val) {
257 0 : m_options->ui.physicalDotsPerInch = val;
258 : } else {
259 0 : LOGE() << "Option: -D not recognized DPI value: " << m_parser.value("D");
260 : }
261 : }
262 :
263 0 : if (m_parser.isSet("T")) {
264 0 : std::optional<int> val = intValue("T");
265 0 : if (val) {
266 0 : m_options->exportImage.trimMarginPixelSize = val;
267 : } else {
268 0 : LOGE() << "Option: -T not recognized trim value: " << m_parser.value("T");
269 : }
270 : }
271 :
272 0 : if (m_parser.isSet("M")) {
273 0 : m_options->importMidi.operationsFile = fromUserInputPath(m_parser.value("M"));
274 : }
275 :
276 0 : if (m_parser.isSet("b")) {
277 0 : std::optional<int> val = intValue("b");
278 0 : if (val) {
279 0 : m_options->exportAudio.mp3Bitrate = val;
280 : } else {
281 0 : LOGE() << "Option: -b not recognized bitrate value: " << m_parser.value("b");
282 : }
283 : }
284 :
285 0 : if (m_parser.isSet("template-mode")) {
286 0 : m_options->notation.templateModeEnabled = true;
287 : }
288 :
289 0 : if (m_parser.isSet("t")) {
290 0 : m_options->notation.testModeEnabled = true;
291 : }
292 :
293 0 : if (m_parser.isSet("session-type")) {
294 0 : m_options->startup.type = m_parser.value("session-type").toStdString();
295 : }
296 :
297 0 : if (m_parser.isSet("register-audio-plugin")) {
298 0 : m_options->runMode = IApplication::RunMode::AudioPluginRegistration;
299 0 : m_options->audioPluginRegistration.pluginPath = fromUserInputPath(m_parser.value("register-audio-plugin"));
300 0 : m_options->audioPluginRegistration.outputFile = fromUserInputPath(m_parser.value("register-audio-plugin-out"));
301 : }
302 :
303 : // Converter mode
304 0 : if (m_parser.isSet("r")) {
305 0 : std::optional<float> val = floatValue("r");
306 0 : if (val) {
307 0 : m_options->exportImage.pngDpiResolution = val;
308 : } else {
309 0 : LOGE() << "Option: -r not recognized DPI value: " << m_parser.value("r");
310 : }
311 : }
312 :
313 0 : if (m_parser.isSet("o")) {
314 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
315 0 : m_options->converterTask.type = ConvertType::File;
316 0 : m_options->converterTask.inputFile = firstScoreFile(scorefiles);
317 0 : m_options->converterTask.outputFile = fromUserInputPath(m_parser.value("o"));
318 :
319 : // Only if "-o" is set "transpose" has some meaning
320 0 : if (m_parser.isSet("transpose")) {
321 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::ScoreTransposeOptions] = m_parser.value("transpose");
322 : }
323 :
324 0 : if (m_parser.isSet("page")) {
325 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::PageNumber] = m_parser.value("page");
326 : }
327 :
328 0 : if (m_parser.isSet("region")) {
329 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::ScoreRegion] = m_parser.value("region");
330 : }
331 : }
332 :
333 0 : if (m_parser.isSet("P")) {
334 0 : if (m_options->converterTask.outputFile.isEmpty()) {
335 0 : LOGE() << "Option: -R no output file specified";
336 : } else {
337 0 : m_options->converterTask.type = ConvertType::ConvertScoreParts;
338 : }
339 : }
340 :
341 0 : if (m_parser.isSet("j")) {
342 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
343 0 : m_options->converterTask.type = ConvertType::Batch;
344 0 : m_options->converterTask.inputFile = fromUserInputPath(m_parser.value("j"));
345 : }
346 :
347 0 : if (m_parser.isSet("score-media")) {
348 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
349 0 : m_options->converterTask.type = ConvertType::ExportScoreMedia;
350 0 : m_options->converterTask.inputFile = firstScoreFile(scorefiles);
351 0 : if (m_parser.isSet("highlight-config")) {
352 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::HighlightConfigPath]
353 0 : = fromUserInputPath(m_parser.value("highlight-config"));
354 : }
355 : }
356 :
357 0 : if (m_parser.isSet("score-meta")) {
358 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
359 0 : m_options->converterTask.type = ConvertType::ExportScoreMeta;
360 0 : m_options->converterTask.inputFile = firstScoreFile(scorefiles);
361 : }
362 :
363 0 : if (m_parser.isSet("score-parts")) {
364 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
365 0 : m_options->converterTask.type = ConvertType::ExportScoreParts;
366 0 : m_options->converterTask.inputFile = firstScoreFile(scorefiles);
367 : }
368 :
369 0 : if (m_parser.isSet("score-parts-pdf")) {
370 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
371 0 : m_options->converterTask.type = ConvertType::ExportScorePartsPdf;
372 0 : m_options->converterTask.inputFile = firstScoreFile(scorefiles);
373 : }
374 :
375 0 : if (m_parser.isSet("score-transpose")) {
376 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
377 0 : m_options->converterTask.type = ConvertType::ExportScoreTranspose;
378 0 : m_options->converterTask.inputFile = firstScoreFile(scorefiles);
379 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::ScoreTransposeOptions] = m_parser.value("score-transpose");
380 : }
381 :
382 0 : if (m_parser.isSet("score-elements")) {
383 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
384 0 : m_options->converterTask.type = ConvertType::ExportScoreElements;
385 0 : m_options->converterTask.inputFile = firstScoreFile(scorefiles);
386 : }
387 :
388 0 : if (m_parser.isSet("source-update")) {
389 0 : QStringList args2 = m_parser.positionalArguments();
390 :
391 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
392 0 : m_options->converterTask.type = ConvertType::SourceUpdate;
393 0 : m_options->converterTask.inputFile = fromUserInputPath(args2.empty() ? "" : args2[0]);
394 :
395 0 : if (args2.size() >= 2) {
396 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::ScoreSource] = args2[1];
397 : } else {
398 0 : LOGW() << "Option: --source-update no source specified";
399 : }
400 0 : }
401 :
402 : // MusicXML
403 0 : if (m_parser.isSet("musicxml-use-default-font")) {
404 0 : m_options->importMusicXml.useDefaultFont = true;
405 : }
406 :
407 0 : if (m_parser.isSet("musicxml-infer-text-type")) {
408 0 : m_options->importMusicXml.inferTextType = true;
409 : }
410 :
411 : // Video
412 : #ifdef MUE_BUILD_IMPEXP_VIDEOEXPORT_MODULE
413 0 : if (m_parser.isSet("score-video")) {
414 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
415 0 : m_options->converterTask.type = ConvertType::ExportScoreVideo;
416 0 : m_options->converterTask.inputFile = firstScoreFile(scorefiles);
417 0 : m_options->converterTask.outputFile = fromUserInputPath(m_parser.value("o"));
418 :
419 0 : if (m_parser.isSet("view-mode")) {
420 0 : NOT_IMPLEMENTED;
421 : }
422 :
423 0 : if (m_parser.isSet("piano")) {
424 0 : NOT_IMPLEMENTED;
425 : }
426 :
427 0 : if (m_parser.isSet("piano-position")) {
428 0 : NOT_IMPLEMENTED;
429 : }
430 :
431 0 : if (m_parser.isSet("resolution")) {
432 0 : m_options->exportVideo.resolution = m_parser.value("resolution").toStdString();
433 : }
434 :
435 0 : if (m_parser.isSet("fps")) {
436 0 : m_options->exportVideo.fps = intValue("fps");
437 : }
438 :
439 0 : if (m_parser.isSet("ls")) {
440 0 : m_options->exportVideo.leadingSec = doubleValue("ls");
441 : }
442 :
443 0 : if (m_parser.isSet("ts")) {
444 0 : m_options->exportVideo.trailingSec = doubleValue("ts");
445 : }
446 :
447 0 : if (m_parser.isSet("no-audio")) {
448 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::NoAudio] = true;
449 : }
450 : }
451 : #endif
452 :
453 0 : if (m_parser.isSet("F") || m_parser.isSet("R")) {
454 0 : m_options->app.revertToFactorySettings = true;
455 : }
456 :
457 0 : if (m_parser.isSet("f")) {
458 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::ForceMode] = true;
459 : }
460 :
461 0 : if (m_parser.isSet("unroll-repeats")) {
462 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::UnrollRepeats] = true;
463 : }
464 :
465 0 : if (m_parser.isSet("S")) {
466 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::StylePath] = fromUserInputPath(m_parser.value("S"));
467 : }
468 :
469 0 : if (m_parser.isSet("sound-profile")) {
470 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::SoundProfile] = m_parser.value("sound-profile");
471 : }
472 :
473 0 : if (m_parser.isSet("tracks-diff")) {
474 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::TracksDiffPath] = m_parser.value("tracks-diff");
475 : }
476 :
477 0 : if (m_parser.isSet("extension")) {
478 0 : m_options->converterTask.params[MuseScoreCmdOptions::ParamKey::ExtensionUri] = m_parser.value("extension");
479 : }
480 :
481 0 : if (m_parser.isSet("gp-linked")) {
482 0 : m_options->guitarPro.linkedTabStaffCreated = true;
483 : }
484 :
485 0 : if (m_parser.isSet("gp-experimental")) {
486 0 : m_options->guitarPro.experimental = true;
487 : }
488 :
489 0 : if (m_options->runMode == IApplication::RunMode::ConsoleApp) {
490 0 : if (m_parser.isSet("migration")) {
491 0 : QString val = m_parser.value("migration");
492 0 : m_options->project.fullMigration = (val == "full") ? true : false;
493 0 : }
494 : }
495 :
496 : // Diagnostic
497 0 : if (m_parser.isSet("diagnostic-output")) {
498 0 : m_options->diagnostic.output = m_parser.value("diagnostic-output");
499 : }
500 :
501 0 : if (m_parser.isSet("diagnostic-gen-drawdata")) {
502 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
503 0 : m_options->diagnostic.type = DiagnosticType::GenDrawData;
504 0 : m_options->diagnostic.input << m_parser.value("diagnostic-gen-drawdata");
505 : }
506 :
507 0 : if (m_parser.isSet("diagnostic-com-drawdata")) {
508 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
509 0 : m_options->diagnostic.type = DiagnosticType::ComDrawData;
510 0 : m_options->diagnostic.input = scorefiles;
511 : }
512 :
513 0 : if (m_parser.isSet("diagnostic-drawdata-to-png")) {
514 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
515 0 : m_options->diagnostic.type = DiagnosticType::DrawDataToPng;
516 0 : m_options->diagnostic.input << m_parser.value("diagnostic-drawdata-to-png");
517 : }
518 :
519 0 : if (m_parser.isSet("diagnostic-drawdiff-to-png")) {
520 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
521 0 : m_options->diagnostic.type = DiagnosticType::DrawDiffToPng;
522 0 : m_options->diagnostic.input = scorefiles;
523 : }
524 :
525 : // Testflow
526 0 : if (m_parser.isSet("test-case")) {
527 0 : m_options->runMode = IApplication::RunMode::ConsoleApp;
528 0 : m_options->testflow.testCaseNameOrFile = fromUserInputPath(m_parser.value("test-case"));
529 : }
530 :
531 0 : if (m_parser.isSet("test-case-context")) {
532 0 : m_options->testflow.testCaseContextNameOrFile = fromUserInputPath(m_parser.value("test-case-context"));
533 : }
534 :
535 0 : if (m_parser.isSet("test-case-context-value")) {
536 0 : m_options->testflow.testCaseContextValue = m_parser.value("test-case-context-value");
537 : }
538 :
539 0 : if (m_parser.isSet("test-case-func")) {
540 0 : m_options->testflow.testCaseFunc = m_parser.value("test-case-func");
541 : }
542 :
543 0 : if (m_parser.isSet("test-case-func-args")) {
544 0 : m_options->testflow.testCaseFuncArgs = m_parser.value("test-case-func-args");
545 : }
546 :
547 : // Startup
548 0 : if (m_options->runMode == IApplication::RunMode::GuiApp) {
549 0 : if (!scorefiles.isEmpty()) {
550 0 : m_options->startup.scoreUrl = QUrl::fromUserInput(scorefiles[0], QDir::currentPath(), QUrl::AssumeLocalFile);
551 : }
552 :
553 0 : if (m_parser.isSet("score-display-name-override")) {
554 0 : m_options->startup.scoreDisplayNameOverride = m_parser.value("score-display-name-override");
555 : }
556 : }
557 0 : }
558 :
559 0 : void CommandLineParser::processBuiltinArgs(const QCoreApplication& app)
560 : {
561 : //! NOTE: some options require an instance of QCoreApplication
562 0 : m_parser.process(app);
563 0 : }
564 :
565 0 : IApplication::RunMode CommandLineParser::runMode() const
566 : {
567 0 : return m_options->runMode;
568 : }
569 :
570 0 : std::shared_ptr<MuseScoreCmdOptions> CommandLineParser::options() const
571 : {
572 0 : return m_options;
573 : }
574 :
575 0 : void CommandLineParser::printLongVersion() const
576 : {
577 0 : if (BaseApplication::appUnstable()) {
578 0 : printf("MuseScore: Music Score Editor\nUnstable Prerelease for Version %s; Build %s\n",
579 0 : BaseApplication::appVersion().toStdString().c_str(), BaseApplication::appRevision().toStdString().c_str());
580 : } else {
581 0 : printf("MuseScore: Music Score Editor; Version %s; Build %s\n",
582 0 : BaseApplication::appVersion().toStdString().c_str(), BaseApplication::appRevision().toStdString().c_str());
583 : }
584 0 : }
|