Skip to content

Commit e28e3f4

Browse files
committed
app: project: Add -i,--inactive flag to west list
In order for users to see which projects are currently inactive, add a new -i/--inactive flag to list only inactive projects. Just like with --all, giving an explicit list of projects overrides the flag. Signed-off-by: Carles Cufi <[email protected]>
1 parent 6202160 commit e28e3f4

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

src/west/app/project.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ def do_add_parser(self, parser_adder):
428428
epilog=f'''\
429429
{ACTIVE_PROJECTS_HELP}
430430
431+
Note: To list only inactive projects you can use --inactive.
432+
431433
FORMAT STRINGS
432434
--------------
433435
@@ -453,11 +455,15 @@ def do_add_parser(self, parser_adder):
453455
that the project has been cloned.
454456
- cloned: "cloned" if the project has been cloned, "not-cloned"
455457
otherwise
458+
- active: "active" if the project is currently active, "inactive" otherwise
456459
- clone_depth: project clone depth if specified, "None" otherwise
457460
- groups: project groups, as a comma-separated list
458461
''')
459-
parser.add_argument('-a', '--all', action='store_true',
460-
help='include inactive projects'),
462+
group = parser.add_mutually_exclusive_group(required=False)
463+
group.add_argument('-a', '--all', action='store_true',
464+
help='include inactive projects'),
465+
group.add_argument('-i', '--inactive', action='store_true',
466+
help='list only inactive projects'),
461467
parser.add_argument('--manifest-path-from-yaml', action='store_true',
462468
help='''print the manifest repository's path
463469
according to the manifest file YAML, which may
@@ -491,15 +497,27 @@ def cloned_thunk(project):
491497

492498
return "cloned" if project.is_cloned() else "not-cloned"
493499

500+
def active_thunk(project):
501+
self.die_if_no_git()
502+
503+
return "active" if self.manifest.is_active(project) else "inactive"
504+
494505
def delay(func, project):
495506
return DelayFormat(partial(func, project))
496507

508+
if args.inactive and args.projects:
509+
self.parser.error('-i cannot be combined with an explicit project '
510+
'list')
511+
497512
for project in self._projects(args.projects):
498-
# Skip inactive projects unless the user said
513+
# Include the project based on the inactive flag. If the flag is
514+
# set, include only inactive projects. Otherwise, include only
515+
# active ones.
516+
include = self.manifest.is_active(project) != bool(args.inactive)
517+
# Skip active or inactive projects unless the user said
499518
# --all or named some projects explicitly.
500-
if not (args.all or args.projects or
501-
self.manifest.is_active(project)):
502-
self.dbg(f'{project.name}: skipping inactive project')
519+
if not (args.all or args.projects or include):
520+
self.dbg(f'{project.name}: skipping project')
503521
continue
504522

505523
# Spelling out the format keys explicitly here gives us
@@ -538,6 +556,7 @@ def delay(func, project):
538556
revision=project.revision or 'N/A',
539557
clone_depth=project.clone_depth or "None",
540558
cloned=delay(cloned_thunk, project),
559+
active=delay(active_thunk, project),
541560
sha=delay(sha_thunk, project),
542561
groups=','.join(project.groups))
543562
except KeyError as e:

tests/test_project.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,22 @@ def check(command_string, expected):
225225
'bar .. path-for-bar',
226226
'baz .baz-group. baz'])
227227

228+
check(_list_f('{name} .{groups}. {path} {active}') + ['--inactive'],
229+
['foo .foo-group-1,foo-group-2. foo inactive',
230+
'baz .baz-group. baz inactive'])
231+
232+
check(_list_f("{name} .{groups}. {path} {active}") + ['--all'] + 'foo bar'.split(),
233+
['foo .foo-group-1,foo-group-2. foo inactive',
234+
'bar .. path-for-bar active'])
235+
236+
with pytest.raises(subprocess.CalledProcessError):
237+
cmd(_list_f("{name} .{groups}. {path}") + ['--inactive'] + 'foo bar'.split())
238+
228239
cmd('config manifest.group-filter +foo-group-1')
229-
check(_list_f('{name} .{groups}. {path}'),
230-
['manifest .. zephyr',
231-
'foo .foo-group-1,foo-group-2. foo',
232-
'bar .. path-for-bar'])
240+
check(_list_f('{name} .{groups}. {path} {active}'),
241+
['manifest .. zephyr active',
242+
'foo .foo-group-1,foo-group-2. foo active',
243+
'bar .. path-for-bar active'])
233244

234245

235246
def test_list_sha(west_update_tmpdir):

0 commit comments

Comments
 (0)