Skip to content

Commit 8b5c612

Browse files
committed
[nrf fromtree] scripts: runners: Generalize the --dry-run option
Move the argparse.add_argument() call to the abstract base class and augment the RunnerCaps class with a dry_run parameter. Signed-off-by: Carles Cufi <[email protected]> (cherry picked from commit 48e0481)
1 parent 3b0588e commit 8b5c612

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

scripts/west_commands/runners/core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ class RunnerCaps:
318318
hide_load_files: bool = False
319319
rtt: bool = False # This capability exists separately from the rtt command
320320
# to allow other commands to use the rtt address
321+
dry_run: bool = False
321322

322323
def __post_init__(self):
323324
if self.mult_dev_ids and not self.dev_id:
@@ -639,6 +640,10 @@ def add_parser(cls, parser):
639640
else:
640641
parser.add_argument('--rtt-address', help=argparse.SUPPRESS)
641642

643+
parser.add_argument('--dry-run', action='store_true',
644+
help=('''Print all the commands without actually
645+
executing them''' if caps.dry_run else argparse.SUPPRESS))
646+
642647
# Runner-specific options.
643648
cls.do_add_parser(parser)
644649

@@ -685,6 +690,8 @@ def create(cls, cfg: RunnerConfig,
685690
_missing_cap(cls, '--file-type')
686691
if args.rtt_address and not caps.rtt:
687692
_missing_cap(cls, '--rtt-address')
693+
if args.dry_run and not caps.dry_run:
694+
_missing_cap(cls, '--dry-run')
688695

689696
ret = cls.do_create(cfg, args)
690697
if args.erase:

scripts/west_commands/runners/nrf_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ def __init__(self, cfg, family, softreset, pinreset, dev_id, erase=False,
7575
self.tool_opt += opts
7676

7777
@classmethod
78-
def _capabilities(cls, mult_dev_ids=False):
78+
def _capabilities(cls, mult_dev_ids=False, dry_run=False):
7979
return RunnerCaps(commands={'flash'}, dev_id=True,
8080
mult_dev_ids=mult_dev_ids, erase=True, reset=True,
81-
tool_opt=True)
81+
tool_opt=True, dry_run=dry_run)
8282

8383
@classmethod
8484
def _dev_id_help(cls) -> str:

scripts/west_commands/runners/nrfutil.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def name(cls):
3737

3838
@classmethod
3939
def capabilities(cls):
40-
return NrfBinaryRunner._capabilities(mult_dev_ids=True)
40+
return NrfBinaryRunner._capabilities(mult_dev_ids=True, dry_run=True)
4141

4242
@classmethod
4343
def dev_id_help(cls) -> str:
@@ -65,10 +65,6 @@ def do_add_parser(cls, parser):
6565
parser.add_argument('--ext-mem-config-file', required=False,
6666
dest='ext_mem_config_file',
6767
help='path to an JSON file with external memory configuration')
68-
parser.add_argument('--dry-run', required=False,
69-
action='store_true',
70-
help='''Generate all the commands without actually
71-
executing them''')
7268

7369
def _exec(self, args, force=False):
7470
jout_all = []

0 commit comments

Comments
 (0)