13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
15
16
- import click
17
16
import library_generation .utilities as util
17
+ import click
18
18
import os
19
19
from library_generation .generate_composed_library import generate_composed_library
20
+ from library_generation .model .generation_config import GenerationConfig
20
21
from library_generation .model .generation_config import from_yaml
22
+ from library_generation .model .library_config import LibraryConfig
21
23
from library_generation .utils .monorepo_postprocessor import monorepo_postprocessing
22
24
23
25
@@ -39,13 +41,22 @@ def main(ctx):
39
41
""" ,
40
42
)
41
43
@click .option (
42
- "--target-library-api-shortname " ,
44
+ "--target-library-names " ,
43
45
required = False ,
46
+ default = None ,
44
47
type = str ,
45
48
help = """
46
- If specified, only the `library` whose api_shortname equals to
47
- target-library-api-shortname will be generated.
49
+ A list of libraries will be generated.
50
+
51
+ If specified, only the `library` whose library_name is in
52
+ target-library-names will be generated.
48
53
If not specified, all libraries in the configuration yaml will be generated.
54
+
55
+ The input string will be parsed to a list of string with comma as the
56
+ separator.
57
+
58
+ For example, apigeeconnect,alloydb-connectors will be parsed as a
59
+ list of two strings, apigeeconnect and alloydb-connectors.
49
60
""" ,
50
61
)
51
62
@click .option (
@@ -61,39 +72,46 @@ def main(ctx):
61
72
)
62
73
def generate (
63
74
generation_config_yaml : str ,
64
- target_library_api_shortname : str ,
75
+ target_library_names : str ,
65
76
repository_path : str ,
66
77
):
67
78
generate_from_yaml (
68
79
generation_config_yaml = generation_config_yaml ,
69
80
repository_path = repository_path ,
70
- target_library_api_shortname = target_library_api_shortname ,
81
+ target_library_names = target_library_names .split ("," )
82
+ if target_library_names is not None
83
+ else target_library_names ,
71
84
)
72
85
73
86
74
87
def generate_from_yaml (
75
88
generation_config_yaml : str ,
76
89
repository_path : str ,
77
- target_library_api_shortname : str = None ,
90
+ target_library_names : list [ str ] = None ,
78
91
) -> None :
79
92
"""
80
93
Parses a config yaml and generates libraries via
81
94
generate_composed_library.py
95
+ :param generation_config_yaml: Path to generation_config.yaml that contains
96
+ the metadata about library generation
97
+ :param repository_path: If specified, the generated files will be sent to
98
+ this location. If not specified, the repository will be generated to the
99
+ current working directory.
100
+ :param target_library_names: a list of libraries to be generated.
101
+ If specified, only the library whose library_name is in
102
+ target-library-names will be generated.
103
+ If specified with an empty list, then no library will be generated.
104
+ If not specified, all libraries in the configuration yaml will be generated.
82
105
"""
83
- # convert paths to absolute paths so they can be correctly referenced in
106
+ # convert paths to absolute paths, so they can be correctly referenced in
84
107
# downstream scripts
85
108
generation_config_yaml = os .path .abspath (generation_config_yaml )
86
109
repository_path = os .path .abspath (repository_path )
87
110
88
111
config = from_yaml (generation_config_yaml )
89
- target_libraries = config .libraries
90
- if target_library_api_shortname is not None :
91
- target_libraries = [
92
- library
93
- for library in config .libraries
94
- if library .api_shortname == target_library_api_shortname
95
- ]
96
-
112
+ target_libraries = get_target_libraries (
113
+ config = config , target_library_names = target_library_names
114
+ )
97
115
repo_config = util .prepare_repo (
98
116
gen_config = config , library_config = target_libraries , repo_path = repository_path
99
117
)
@@ -118,5 +136,22 @@ def generate_from_yaml(
118
136
)
119
137
120
138
121
- if __name__ == "__main__" :
122
- main ()
139
+ def get_target_libraries (
140
+ config : GenerationConfig , target_library_names : list [str ] = None
141
+ ) -> list [LibraryConfig ]:
142
+ """
143
+ Returns LibraryConfig objects whose library_name is in target_library_names.
144
+
145
+ :param config: a GenerationConfig object.
146
+ :param target_library_names: library_name of target libraries.
147
+ If not specified, all libraries in the given config will be returned.
148
+ :return: LibraryConfig objects.
149
+ """
150
+ if target_library_names is None :
151
+ return config .libraries
152
+ target_libraries = set (target_library_names )
153
+ return [
154
+ library
155
+ for library in config .libraries
156
+ if library .get_library_name () in target_libraries
157
+ ]
0 commit comments