2424GENERATE_REQUEST_FILE = "generate-request.json"
2525
2626
27- # Helper function that reads a json file path and returns the loaded json content.
2827def _read_json_file (path ):
28+ """Helper function that reads a json file path and returns the loaded json content.
29+
30+ Args:
31+ path (str): The file path to read.
32+
33+ Returns:
34+ dict: The parsed JSON content.
35+
36+ Raises:
37+ FileNotFoundError: If the file is not found at the specified path.
38+ json.JSONDecodeError: If the file does not contain valid JSON.
39+ IOError: If there is an issue reading the file.
40+ """
2941 with open (path , "r" ) as f :
3042 return json .load (f )
3143
3244
33- def handle_configure (dry_run = False ):
34- # TODO(https://github.com/googleapis/librarian/issues/466): Implement configure command.
45+ def handle_configure ():
46+ # TODO(https://github.com/googleapis/librarian/issues/466): Implement configure command and update docstring .
3547 logger .info ("'configure' command executed." )
3648
3749
38- def handle_generate (dry_run = False ):
50+ def handle_generate ():
51+ """The main coordinator for the code generation process.
52+
53+ This function orchestrates the generation of a client library by reading a
54+ `librarian/generate-request.json` file, determining the necessary Bazel rule for each API, and
55+ (in future steps) executing the build.
56+
57+ Raises:
58+ ValueError: If the `generate-request.json` file is not found or read.
59+ """
3960
4061 # Read a generate-request.json file
41- if not dry_run :
42- try :
43- request_data = _read_json_file ( f" { LIBRARIAN_DIR } / { GENERATE_REQUEST_FILE } " )
44- except Exception as e :
45- logger . error ( f"failed to read { LIBRARIAN_DIR } /{ GENERATE_REQUEST_FILE } : { e } " )
46- sys . exit ( 1 )
62+ try :
63+ request_data = _read_json_file ( f" { LIBRARIAN_DIR } / { GENERATE_REQUEST_FILE } " )
64+ except Exception as e :
65+ raise ValueError (
66+ f"failed to read { LIBRARIAN_DIR } /{ GENERATE_REQUEST_FILE } "
67+ ) from e
4768
48- logger .info (json .dumps (request_data , indent = 2 ))
69+ logger .info (json .dumps (request_data , indent = 2 ))
4970
50- # TODO(https://github.com/googleapis/librarian/issues/448): Implement generate command.
71+ # TODO(https://github.com/googleapis/librarian/issues/448): Implement generate command and update docstring .
5172 logger .info ("'generate' command executed." )
5273
5374
54- def handle_build (dry_run = False ):
55- # TODO(https://github.com/googleapis/librarian/issues/450): Implement build command.
75+ def handle_build ():
76+ # TODO(https://github.com/googleapis/librarian/issues/450): Implement build command and update docstring .
5677 logger .info ("'build' command executed." )
5778
5879
@@ -62,11 +83,6 @@ def handle_build(dry_run=False):
6283 dest = "command" , required = True , help = "Available commands"
6384 )
6485
65- # This flag is needed for testing.
66- parser .add_argument (
67- "--dry-run" , action = "store_true" , help = "Perform a dry run for testing purposes."
68- )
69-
7086 # Define commands
7187 handler_map = {
7288 "configure" : handle_configure ,
@@ -87,4 +103,4 @@ def handle_build(dry_run=False):
87103 sys .exit (1 )
88104
89105 args = parser .parse_args ()
90- args .func (dry_run = args . dry_run )
106+ args .func ()
0 commit comments