Skip to content

Commit 1aa564f

Browse files
committed
Slightly change the logic so 'detect' is also a valid config option
1 parent efe530e commit 1aa564f

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

mbed/mbed.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,20 +1323,21 @@ def get_env(self):
13231323
return env
13241324

13251325
def get_target(self, target=None):
1326-
if target:
1327-
if target.lower() == 'detect' or target.lower() == 'auto':
1328-
targets = self.get_detected_targets()
1329-
if targets == False:
1330-
error("The target detection requires that the 'mbed-ls' python module is installed.")
1331-
elif len(targets) > 1:
1332-
error("Multiple targets were detected.\nOnly 1 target board should be connected to your system when you use the '-m auto' switch.")
1333-
elif len(targets) == 0:
1334-
error("No targets were detected.\nPlease make sure a target board to this system.")
1335-
else:
1336-
action("Detected \"%s\" connected to \"%s\" and using com port \"%s\"" % (targets[0]['name'], targets[0]['mount'], targets[0]['serial']))
1337-
target = targets[0]['name']
1338-
else:
1339-
target = self.get_cfg('TARGET')
1326+
target_cfg = self.get_cfg('TARGET')
1327+
target = target if target else target_cfg
1328+
1329+
if target and (target.lower() == 'detect' or target.lower() == 'auto'):
1330+
targets = self.get_detected_targets()
1331+
if targets == False:
1332+
error("The target detection requires that the 'mbed-ls' python module is installed.")
1333+
elif len(targets) > 1:
1334+
error("Multiple targets were detected.\nOnly 1 target board should be connected to your system when you use the '-m auto' switch.")
1335+
elif len(targets) == 0:
1336+
error("No targets were detected.\nPlease make sure a target board to this system.")
1337+
else:
1338+
action("Detected \"%s\" connected to \"%s\" and using com port \"%s\"" % (targets[0]['name'], targets[0]['mount'], targets[0]['serial']))
1339+
target = targets[0]['name']
1340+
13401341
if target is None:
13411342
error("Please specify target using the -m switch or set default target using command 'mbed target'", 1)
13421343
return target

0 commit comments

Comments
 (0)