@@ -268,6 +268,7 @@ static protected void initRequirements() {
268
268
}
269
269
270
270
271
+ protected static enum ACTION { GUI , VERIFY , UPLOAD };
271
272
public Base (String [] args ) throws Exception {
272
273
platform .init (this );
273
274
@@ -318,23 +319,29 @@ public Base(String[] args) throws Exception {
318
319
// Setup board-dependent variables.
319
320
onBoardOrPortChange ();
320
321
321
- boolean doUpload = false ;
322
- boolean doVerify = false ;
322
+ ACTION action = ACTION .GUI ;
323
323
boolean doVerboseBuild = false ;
324
324
boolean doVerboseUpload = false ;;
325
325
String selectBoard = null ;
326
326
String selectPort = null ;
327
327
String currentDirectory = System .getProperty ("user.dir" );
328
328
List <String > filenames = new LinkedList <String >();
329
329
330
+ // Map of possible actions and corresponding options
331
+ final Map <String , ACTION > actions = new HashMap <String , ACTION >();
332
+ actions .put ("--verify" , ACTION .VERIFY );
333
+ actions .put ("--upload" , ACTION .UPLOAD );
334
+
330
335
// Check if any files were passed in on the command line
331
336
for (int i = 0 ; i < args .length ; i ++) {
332
- if (args [i ].equals ("--upload" )) {
333
- doUpload = true ;
334
- continue ;
335
- }
336
- if (args [i ].equals ("--verify" )) {
337
- doVerify = true ;
337
+ ACTION a = actions .get (args [i ]);
338
+ if (a != null ) {
339
+ if (action != ACTION .GUI ) {
340
+ String [] valid = actions .keySet ().toArray (new String [0 ]);
341
+ String mess = I18n .format (_ ("Can only pass one of: {0}" ), PApplet .join (valid , ", " ));
342
+ showError (null , mess , 3 );
343
+ }
344
+ action = a ;
338
345
continue ;
339
346
}
340
347
if (args [i ].equals ("--verbose" ) || args [i ].equals ("-v" )) {
@@ -391,7 +398,7 @@ public Base(String[] args) throws Exception {
391
398
filenames .add (args [i ]);
392
399
}
393
400
394
- if ((doUpload || doVerify ) && filenames .size () != 1 )
401
+ if ((action == ACTION . UPLOAD || action == ACTION . VERIFY ) && filenames .size () != 1 )
395
402
showError (null , _ ("Must specify exactly one sketch file" ), 3 );
396
403
397
404
for (String path : filenames ) {
@@ -412,17 +419,17 @@ public Base(String[] args) throws Exception {
412
419
path = new File (currentDirectory , path ).getAbsolutePath ();
413
420
}
414
421
415
- if (handleOpen (path , nextEditorLocation (), !(doUpload || doVerify )) == null ) {
422
+ if (handleOpen (path , nextEditorLocation (), !(action == ACTION . UPLOAD || action == ACTION . VERIFY )) == null ) {
416
423
String mess = I18n .format (_ ("Failed to open sketch: \" {0}\" " ), path );
417
424
// Open failure is fatal in upload/verify mode
418
- if (doUpload || doVerify )
425
+ if (action == ACTION . VERIFY || action == ACTION . UPLOAD )
419
426
showError (null , mess , 2 );
420
427
else
421
428
showWarning (null , mess , null );
422
429
}
423
430
}
424
431
425
- if (doUpload || doVerify ) {
432
+ if (action == ACTION . UPLOAD || action == ACTION . VERIFY ) {
426
433
// Set verbosity for command line build
427
434
Preferences .set ("build.verbose" , "" + doVerboseBuild );
428
435
Preferences .set ("upload.verbose" , "" + doVerboseUpload );
@@ -432,7 +439,7 @@ public Base(String[] args) throws Exception {
432
439
// Do board selection if requested
433
440
processBoardArgument (selectBoard );
434
441
435
- if (doUpload ) {
442
+ if (action == ACTION . UPLOAD ) {
436
443
// Build and upload
437
444
if (selectPort != null )
438
445
editor .selectSerialPort (selectPort );
0 commit comments