Skip to content

Commit a90cb9d

Browse files
Improve commandline handling control flow
This uses a switch on the action value, which makes it more clear what code runs when. No actual behaviour is changed, most of the changes in this commit are indentation changes.
1 parent 0453606 commit a90cb9d

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

app/src/processing/app/Base.java

+40-36
Original file line numberDiff line numberDiff line change
@@ -430,46 +430,50 @@ public Base(String[] args) throws Exception {
430430
}
431431
}
432432

433-
if (action == ACTION.UPLOAD || action == ACTION.VERIFY) {
434-
// Set verbosity for command line build
435-
Preferences.set("build.verbose", "" + doVerboseBuild);
436-
Preferences.set("upload.verbose", "" + doVerboseUpload);
437-
438-
Editor editor = editors.get(0);
439-
440-
// Do board selection if requested
441-
processBoardArgument(selectBoard);
442-
443-
if (action == ACTION.UPLOAD) {
444-
// Build and upload
445-
if (selectPort != null)
446-
editor.selectSerialPort(selectPort);
447-
editor.exportHandler.run();
448-
} else {
449-
// Build only
450-
editor.runHandler.run();
451-
}
452-
453-
// Error during build or upload
454-
int res = editor.status.mode;
455-
if (res == EditorStatus.ERR)
456-
System.exit(1);
433+
switch (action) {
434+
case VERIFY:
435+
case UPLOAD:
436+
// Set verbosity for command line build
437+
Preferences.set("build.verbose", "" + doVerboseBuild);
438+
Preferences.set("upload.verbose", "" + doVerboseUpload);
439+
440+
Editor editor = editors.get(0);
441+
442+
// Do board selection if requested
443+
processBoardArgument(selectBoard);
444+
445+
if (action == ACTION.UPLOAD) {
446+
// Build and upload
447+
if (selectPort != null)
448+
editor.selectSerialPort(selectPort);
449+
editor.exportHandler.run();
450+
} else {
451+
// Build only
452+
editor.runHandler.run();
453+
}
457454

458-
// No errors exit gracefully
459-
System.exit(0);
460-
}
455+
// Error during build or upload
456+
int res = editor.status.mode;
457+
if (res == EditorStatus.ERR)
458+
System.exit(1);
461459

462-
// Check if there were previously opened sketches to be restored
463-
restoreSketches();
460+
// No errors exit gracefully
461+
System.exit(0);
462+
break;
463+
case GUI:
464+
// Check if there were previously opened sketches to be restored
465+
restoreSketches();
464466

465-
// Create a new empty window (will be replaced with any files to be opened)
466-
if (editors.isEmpty()) {
467-
handleNew();
468-
}
467+
// Create a new empty window (will be replaced with any files to be opened)
468+
if (editors.isEmpty()) {
469+
handleNew();
470+
}
469471

470-
// Check for updates
471-
if (Preferences.getBoolean("update.check")) {
472-
new UpdateCheck(this);
472+
// Check for updates
473+
if (Preferences.getBoolean("update.check")) {
474+
new UpdateCheck(this);
475+
}
476+
break;
473477
}
474478
}
475479

0 commit comments

Comments
 (0)