1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16- import click
1716import library_generation .utilities as util
17+ import click
1818import os
1919from library_generation .generate_composed_library import generate_composed_library
20+ from library_generation .model .generation_config import GenerationConfig
2021from library_generation .model .generation_config import from_yaml
22+ from library_generation .model .library_config import LibraryConfig
2123from library_generation .utils .monorepo_postprocessor import monorepo_postprocessing
2224
2325
@@ -39,13 +41,22 @@ def main(ctx):
3941 """ ,
4042)
4143@click .option (
42- "--target-library-api-shortname " ,
44+ "--target-library-names " ,
4345 required = False ,
46+ default = None ,
4447 type = str ,
4548 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.
4853 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.
4960 """ ,
5061)
5162@click .option (
@@ -61,39 +72,46 @@ def main(ctx):
6172)
6273def generate (
6374 generation_config_yaml : str ,
64- target_library_api_shortname : str ,
75+ target_library_names : str ,
6576 repository_path : str ,
6677):
6778 generate_from_yaml (
6879 generation_config_yaml = generation_config_yaml ,
6980 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 ,
7184 )
7285
7386
7487def generate_from_yaml (
7588 generation_config_yaml : str ,
7689 repository_path : str ,
77- target_library_api_shortname : str = None ,
90+ target_library_names : list [ str ] = None ,
7891) -> None :
7992 """
8093 Parses a config yaml and generates libraries via
8194 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.
82105 """
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
84107 # downstream scripts
85108 generation_config_yaml = os .path .abspath (generation_config_yaml )
86109 repository_path = os .path .abspath (repository_path )
87110
88111 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+ )
97115 repo_config = util .prepare_repo (
98116 gen_config = config , library_config = target_libraries , repo_path = repository_path
99117 )
@@ -118,5 +136,22 @@ def generate_from_yaml(
118136 )
119137
120138
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