Commit ec01e0f8 authored by Martí Bolívar's avatar Martí Bolívar Committed by Anas Nashif
Browse files

scripts: zephyr_flash_debug: add 'runners' command



This just prints the available runner classes.

Signed-off-by: default avatarMarti Bolivar <marti@opensourcefoundries.com>
parent 57d5717b
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -21,6 +21,11 @@ import sys
from runner.core import ZephyrBinaryRunner


def print_runners_handler(args):
    for cls in ZephyrBinaryRunner.get_runners():
        print(cls.name())


def runner_handler(cls, args):
    runner = cls.create_from_args(args)
    # This relies on ZephyrBinaryRunner.add_parser() having command as
@@ -47,18 +52,30 @@ def main():
    # $ZEPHYR_BASE/.../SCRIPT.py [-v|--verbose] RUNNER [--runner-options]
    #
    # Note that --verbose comes *before* RUNNER, not after!
    #
    # Other commands (for now just the "runners" command, which prints
    # the available runners) are handled the same way:
    #
    # $ZEPHYR_BASE/.../SCRIPT.py runners
    top_parser = argparse.ArgumentParser()
    top_parser.add_argument('-v', '--verbose',
                            default=False, action='store_true',
                            help='If set, enable verbose output.')
    sub_parsers = top_parser.add_subparsers(dest='runner')
    sub_parsers = top_parser.add_subparsers(dest='top_command')

    # Handlers for each subcommand.
    handlers = {}

    # The 'runners' command just prints the runners. It takes no arguments.
    sub_parsers.add_parser('runners')
    handlers['runners'] = print_runners_handler

    # Add a sub-command for each runner. (It's a bit hackish for runners
    # to know about argparse, but it's good enough for now.)
    handlers = {}
    for cls in ZephyrBinaryRunner.get_runners():
        if cls.name() in handlers:
            print('Runner {} name is already a sub-command'.format(cls.name()),
            print('Runner {} name is already a top-level command'.format(
                      cls.name()),
                  file=sys.sterr)
            sys.exit(1)
        sub_parser = sub_parsers.add_parser(cls.name())
@@ -66,12 +83,13 @@ def main():
        handlers[cls.name()] = functools.partial(runner_handler, cls)

    args = top_parser.parse_args()
    if args.runner is None:
        runners = ', '.join(handlers.keys())
        print('Missing runner; choices: {}'.format(runners), file=sys.stderr)
    if args.top_command is None:
        choices = ', '.join(handlers.keys())
        print('Missing command or runner; choices: {}'.format(choices),
              file=sys.stderr)
        sys.exit(1)
    try:
        handlers[args.runner](args)
        handlers[args.top_command](args)
    except Exception as e:
        print('Error: {}'.format(e), file=sys.stderr)
        raise