Skip to content

Commit cdcf2a6

Browse files
committed
Handle defaults for toolchain and target commands through default_() routine.
Introduce default command which allows other defaults to be set, such as protocol (#142)
1 parent ea20373 commit cdcf2a6

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

mbed/mbed.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,32 +1773,31 @@ def export(ide=None, mcu=None):
17731773
dict(name='name', nargs='?', help='Default target name. Example: K64F, NUCLEO_F401RE, NRF51822...'),
17741774
help='Set default target for the current program.')
17751775
def target_(name=None):
1776-
# Find the root of the program
1777-
program = Program(os.getcwd(), False)
1778-
# Change directories to the program root to use mbed OS tools
1779-
with cd(program.path):
1780-
if name is None:
1781-
name = program.get_cfg('TARGET')
1782-
action(('The default target for program "%s" is "%s"' % (program.name, name)) if name else 'No default target is specified for program "%s"' % program.name)
1783-
else:
1784-
program.set_cfg('TARGET', name)
1785-
action('"%s" now set as default target for program "%s"' % (name, program.name))
1776+
return default_('target', name)
17861777

17871778
@subcommand('toolchain',
17881779
dict(name='name', nargs='?', help='Default toolchain name. Example: ARM, uARM, GCC_ARM, IAR'),
17891780
help='Sets default toolchain for the current program.')
17901781
def toolchain_(name=None):
1782+
return default_('toolchain', name)
1783+
1784+
# Generic config command
1785+
@subcommand('default',
1786+
dict(name='name', help='Variable name. E.g. "target", "toolchain", "protocol"'),
1787+
dict(name='value', nargs='?', help='Value. Will show the currently set default value for a variable if not specified.'),
1788+
help='Sets or get program default options.')
1789+
def default_(name, value=None):
17911790
# Find the root of the program
17921791
program = Program(os.getcwd(), False)
1793-
# Change directories to the program root to use mbed OS tools
1792+
# Change current dir to program root
17941793
with cd(program.path):
1795-
if name is None:
1796-
name = program.get_cfg('TOOLCHAIN')
1797-
action(('The default toolchain for program "%s" is "%s"' % (program.name, name)) if name else 'No default toolchain is specified for program "%s"' % program.name)
1794+
var = str(name).upper()
1795+
if value is None:
1796+
value = program.get_cfg(var)
1797+
action(('%s' % value) if value else 'No default %s set in program "%s"' % (name, program.name))
17981798
else:
1799-
program.set_cfg('TOOLCHAIN', name)
1800-
action('"%s" now set as default toolchain for program "%s"' % (name, program.name))
1801-
1799+
program.set_cfg(var, value)
1800+
action('%s now set as default %s in program "%s"' % (value, name, program.name))
18021801

18031802
# Parse/run command
18041803
if len(sys.argv) <= 1:

0 commit comments

Comments
 (0)