Skip to content

Commit 7fa06cd

Browse files
committed
feat(cli): allow filtering apps via a csv file
1 parent b687600 commit 7fa06cd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

gitops/utils/apps.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pathlib
12
import sys
23
from pathlib import Path
34
from typing import Literal
@@ -77,15 +78,23 @@ def get_apps( # noqa: C901
7778
`exclude`. The incoming filter and exclude params may come in as a list or commastring.
7879
For the purpose of this filtering, app names and image tag prefixes are also considered as
7980
tags. For instance, you can do get_apps(tags=[emeriss, production], exclude=[arafire]).
81+
82+
If filter is a file like name; read a list of app names from the file.
83+
8084
Calling this method without any args returns all apps.
8185
There are three modes for communicating selected apps to the user:
8286
- PROMPT: Prints selected apps and asks for confirmation to proceed.
8387
- PREVIEW: Prints selected apps then proceeds.
8488
- SILENT: Proceeds without printing.
8589
Apps with the `inactive` tag are excluded by default, unless requested otherwise.
8690
"""
91+
app_names: list[str] = []
92+
8793
if filter == "all":
8894
filter = set()
95+
elif isinstance(filter, str) and pathlib.Path(filter).is_file():
96+
app_names = [f.strip() for f in pathlib.Path(filter).read_text().splitlines() if f.strip()]
97+
filter = set()
8998
else:
9099
filter = set(filter.split(",") if filter and isinstance(filter, str) else filter)
91100

@@ -114,7 +123,12 @@ def get_apps( # noqa: C901
114123

115124
tags = set(app.tags + pseudotags)
116125
existing_tags |= tags
117-
if filter <= tags and not exclude & tags:
126+
127+
# Decide whether to include the app based on the filter and exclude tags.
128+
if app_names:
129+
if app.name in app_names:
130+
apps.append(app)
131+
elif filter <= tags and not exclude & tags:
118132
apps.append(app)
119133

120134
validate_tags(filter | exclude, existing_tags)

0 commit comments

Comments
 (0)