@@ -395,21 +395,8 @@ public Base(String[] args) throws Exception {
395
395
Thread .sleep (10 );
396
396
397
397
// Do board selection if requested
398
- if (selectBoard != null ) {
399
- String [] split = selectBoard .split (":" );
400
-
401
- TargetBoard targetBoard = getTargetPlatform (split [0 ], split [1 ]).getBoard (split [2 ]);
402
- selectBoard (targetBoard );
403
-
404
- if (split .length > 3 ) {
405
- String [] customsParts = split [3 ].split ("," );
406
- for (String customParts : customsParts ) {
407
- String [] keyValue = customParts .split ("=" );
408
- Preferences .set ("custom_" + keyValue [0 ].trim (), targetBoard .getId () + "_" + keyValue [1 ].trim ());
409
- }
410
- }
411
- }
412
-
398
+ processBoardArgument (selectBoard );
399
+
413
400
if (doUpload ) {
414
401
// Build and upload
415
402
if (selectPort != null )
@@ -444,6 +431,54 @@ public Base(String[] args) throws Exception {
444
431
}
445
432
}
446
433
434
+ protected void processBoardArgument (String selectBoard ) {
435
+ // No board selected? Nothing to do
436
+ if (selectBoard == null )
437
+ return ;
438
+
439
+ String [] split = selectBoard .split (":" , 4 );
440
+
441
+ if (split .length < 3 ) {
442
+ showError (null , I18n .format (_ ("{0}: Invalid board name, it should be of the form \" package:arch:board\" or \" package:arch:board:options\" " ), selectBoard ), null );
443
+ }
444
+
445
+ TargetPackage targetPackage = getTargetPackage (split [0 ]);
446
+ if (targetPackage == null ) {
447
+ showError (null , I18n .format (_ ("{0}: Unknown package" ), split [0 ]), null );
448
+ }
449
+
450
+ TargetPlatform targetPlatform = targetPackage .get (split [1 ]);
451
+ if (targetPlatform == null ) {
452
+ showError (null , I18n .format (_ ("{0}: Unknown architecture" ), split [1 ]), null );
453
+ }
454
+
455
+ TargetBoard targetBoard = targetPlatform .getBoard (split [2 ]);
456
+ if (targetBoard == null ) {
457
+ showError (null , I18n .format (_ ("{0}: Unknown board" ), split [2 ]), null );
458
+ }
459
+
460
+ selectBoard (targetBoard );
461
+
462
+ if (split .length > 3 ) {
463
+ String [] options = split [3 ].split ("," );
464
+ for (String option : options ) {
465
+ String [] keyValue = option .split ("=" , 2 );
466
+
467
+ if (keyValue .length != 2 )
468
+ showError (null , I18n .format (_ ("{0}: Invalid option, should be of the form \" name=value\" " ), option , targetBoard .getId ()), null );
469
+ String key = keyValue [0 ].trim ();
470
+ String value = keyValue [1 ].trim ();
471
+
472
+ if (!targetBoard .hasMenu (key ))
473
+ showError (null , I18n .format (_ ("{0}: Invalid option for board \" {1}\" " ), key , targetBoard .getId ()), null );
474
+ if (targetBoard .getMenuLabel (key , value ) == null )
475
+ showError (null , I18n .format (_ ("{0}: Invalid option for \" {1}\" option for board \" {2}\" " ), value , key , targetBoard .getId ()), null );
476
+
477
+ Preferences .set ("custom_" + key , targetBoard .getId () + "_" + value );
478
+ }
479
+ }
480
+ }
481
+
447
482
public Map <String , Map <String , Object >> getBoardsViaNetwork () {
448
483
return new HashMap <String , Map <String , Object >>(boardsViaNetwork );
449
484
}
@@ -2002,6 +2037,15 @@ static public String getAvrBasePath() {
2002
2037
return path ;
2003
2038
}
2004
2039
2040
+ /**
2041
+ * Returns a specific TargetPackage
2042
+ *
2043
+ * @param packageName
2044
+ * @return
2045
+ */
2046
+ static public TargetPackage getTargetPackage (String packageName ) {
2047
+ return packages .get (packageName );
2048
+ }
2005
2049
2006
2050
/**
2007
2051
* Returns the currently selected TargetPlatform.
0 commit comments