adafruit / Adafruit_Adalink

Python wrapper for Segger's J-Link Commander & STMicro STLink V2 to flash various ARM MCUs
MIT License
125 stars 33 forks source link

Refactor to use core as a command line subparser. #3

Closed tdicola closed 9 years ago

tdicola commented 9 years ago

This is a breaking change to Adalink which improves that ability to extend cores by allowing core-specific command line parameters. The change is to make the core a subparser for Python's argparser library and allow each core to add optional command line arguments to their parsing. The functionality that breaks/changes vs. the old behavior is that now the core must be specified as the first positional parameter instead of using the --core parameter.

For example in the past the nRF51822 core could be selected with syntax like:

adalink --core nrf51822 --wipe --program foo.hex

Now this syntax changes to put the core at the beginning without a --core param:

adalink nrf51822 --wipe --program foo.hex

The benefit of this is that each core is a subparser which can define its own custom parameters (in addition to the default ones it will inherit, like --wipe, --program, --info, etc.). You can actually see core-specific help by running --help with a core, like:

adalink nrf51822 --help

You can also see a list of all cores by just running help without any core selected:

adalink --help

To see how to add core-specific parameters see the cores/test.py file for a simple dummy/test core implementation. New class-level methods (kinda like a static class method in C++) can be implemented on a core to add extra arguments to the command line parsing. Each cores initializer will receive as a parameter the parsed command line info which it can read to pull out its custom parameters.

I left all the existing cores alone and didn't change any of their functionality or parameters.