# Path: src/cli/detect.py
# @click.command()
# @click.option(
#     "--original_api_definition_dirs",
#     help="Specify the directories in which to search for the original proto API definition files and imports.",
# )
# @click.option(
#     "--update_api_definition_dirs",
#     help="Specify the directories in which to search for the update proto API definition files and imports.",
# )
# @click.option(
#     "--original_proto_files",
#     help="The path to the files of original proto API definition files.",
# )
# @click.option(
#     "--update_proto_files",
#     help="The path to the files of update proto API definition files.",
# )
# @click.option(
#     "--original_descriptor_set_file_path",
#     help="The path to the original compiled descriptor set file.",
# )
# @click.option(
#     "--update_descriptor_set_file_path",
#     help="The path to the update compiled descriptor set file.",
# )
# @click.option(
#     "--output_json_path",
#     help="The file path for json output which contains all the breaking change findings. The default path is the current folder.",
# )
# @click.option(
#     "--human_readable_message",
#     default=False,
#     is_flag=True,
#     help="Enable the human-readable message output if set to True. Default value is false.",
# )
# @click.option(
#     "--line_numbers/--no_line_numbers",
#     default=True,
#     is_flag=True,
#     help="Show line numbers in the human readable output. True by default, use --no_line_numbers to disable.",
# )
# def detect(
#     original_api_definition_dirs: str,
#     update_api_definition_dirs: str,
#     original_proto_files: str,
#     update_proto_files: str,
#     original_descriptor_set_file_path: str,
#     update_descriptor_set_file_path: str,
#     output_json_path: str,
#     human_readable_message: bool,
#     line_numbers: bool,
# ):
#     """Detect the breaking changes of the original and updated versions of API definition files."""
#     # 1. Read the stdin options and create the Options object for all the command args.
#     # The detector accepts two types of the input:
#     # a) proto API defintion files.
#     # b) compiled FileDescriptorSet file which can be obtained by protocal compiler.
#     options = Options(
#         original_api_definition_dirs=original_api_definition_dirs,
#         update_api_definition_dirs=update_api_definition_dirs,
#         original_proto_files=original_proto_files,
#         update_proto_files=update_proto_files,
#         original_descriptor_set_file_path=original_descriptor_set_file_path,
#         update_descriptor_set_file_path=update_descriptor_set_file_path,
#         human_readable_message=human_readable_message,
#         output_json_path=output_json_path,
#         line_numbers=line_numbers,
#     )
#     # 3. Create protoc command (back up solution) to load the FileDescriptorSet.
#     # It takes options, returns file_descriptor_set.
#     if options.use_descriptor_set():
#         file_set_original = Loader(
#             proto_definition_dirs=None,
#             proto_files=None,
#             descriptor_set=options.original_descriptor_set_file_path,
#         ).get_descriptor_set()
#         file_set_update = Loader(
#             proto_definition_dirs=None,
#             proto_files=None,
#             descriptor_set=options.update_descriptor_set_file_path,
#         ).get_descriptor_set()
#     elif options.use_proto_dirs():
#         file_set_original = Loader(
#             proto_definition_dirs=options.original_api_definition_dirs,
#             proto_files=options.original_proto_files,
#             descriptor_set=None,
#         ).get_descriptor_set()
#         file_set_update = Loader(
#             proto_definition_dirs=options.update_api_definition_dirs,
#             proto_files=options.update_proto_files,
#             descriptor_set=None,
#         ).get_descriptor_set()
#     # 4. Create the detector with two FileDescriptorSet and options.
#     # It creates output_json file and prints human-readable message if the option is enabled.
#     result = Detector(
#         file_set_original, file_set_update, options
#     ).detect_breaking_changes()
#     return len(result)


import unittest
import os
import tempfile
import json
from click.testing import CliRunner
from src.cli.detect import detect
from unittest.mock import patch
from io import StringIO
                + "google/cloud/oslogin/v1/oslogin.proto L202: An existing resource_reference option of the field `name` is removed in message `.google.cloud.oslogin.v1.UpdateSshPublicKeyRequest`.\n",
            )

    def test_oslogin_proto_beta(self):
        with patch("sys.stdout", new=StringIO()):
            runner = CliRunner()
            result = runner.invoke(
                detect,
                [
                    f"--original_api_definition_dirs=googleapis/,{self.COMMON_PROTOS_DIR}",
                    f"--update_api_definition_dirs=googleapis/,{self.COMMON_PROTOS_DIR}",
                    "--original_proto_files=googleapis/google/cloud/oslogin/v1/oslogin.proto",
                    "--update_proto_files=googleapis/google/cloud/oslogin/v1beta/oslogin.proto",
                    "--human_readable_message",
                ],
            )
            self.assertEqual(result.exit_code, 0)
            self.assertEqual(
                result.output,
                "google/cloud/oslogin/v1beta/oslogin.proto L179: Changed field behavior for an existing field `ssh_public_key` in message `.google.cloud.oslogin.v1.ImportSshPublicKeyRequest`.\n",
            )

    def test_pubsub_proto(self):
        pubsub_v1beta2 = os.path.join(
            self.GOOGLEAPI_DIR, "google/pubsub/v1beta2/pubsub.proto"
        )
        pubsub_v1 = os.path.join(self.GOOGLEAPI_DIR, "google/pubsub/v1/pubsub.proto")
        with patch("sys.stdout", new=StringIO()):
            runner = CliRunner()
            result = runner.invoke(

# Path: src/cli/detect.py
# @click.command()
# @click.option(
#     "--original_api_definition_dirs",
#     help="Specify the directories in which to search for the original proto API definition files and imports.",
# )
# @click.option(
#     "--update_api_definition_dirs",
#     help="Specify the directories in which to search for the update proto API definition files and imports.",
# )
# @click.option(
#     "--original_proto_files",
#     help="The path to the files of original proto API definition files.",
# )
# @click.option(
#     "--update_proto_files",
#     help="The path to the files of update proto API definition files.",
# )
# @click.option(
#     "--original_descriptor_set_file_path",
#     help="The path to the original compiled descriptor set file.",
# )
# @click.option(
#     "--update_descriptor_set_file_path",
#     help="The path to the update compiled descriptor set file.",
# )
# @click.option(
#     "--output_json_path",
#     help="The file path for json output which contains all the breaking change findings. The default path is the current folder.",
# )
# @click.option(
#     "--human_readable_message",
#     default=False,
#     is_flag=True,
#     help="Enable the human-readable message output if set to True. Default value is false.",
# )
# @click.option(
#     "--line_numbers/--no_line_numbers",
#     default=True,
#     is_flag=True,
#     help="Show line numbers in the human readable output. True by default, use --no_line_numbers to disable.",
# )
# def detect(
#     original_api_definition_dirs: str,
#     update_api_definition_dirs: str,
#     original_proto_files: str,
#     update_proto_files: str,
#     original_descriptor_set_file_path: str,
#     update_descriptor_set_file_path: str,
#     output_json_path: str,
#     human_readable_message: bool,
#     line_numbers: bool,
# ):
#     """Detect the breaking changes of the original and updated versions of API definition files."""
#     # 1. Read the stdin options and create the Options object for all the command args.
#     # The detector accepts two types of the input:
#     # a) proto API defintion files.
#     # b) compiled FileDescriptorSet file which can be obtained by protocal compiler.
#     options = Options(
#         original_api_definition_dirs=original_api_definition_dirs,
#         update_api_definition_dirs=update_api_definition_dirs,
#         original_proto_files=original_proto_files,
#         update_proto_files=update_proto_files,
#         original_descriptor_set_file_path=original_descriptor_set_file_path,
#         update_descriptor_set_file_path=update_descriptor_set_file_path,
#         human_readable_message=human_readable_message,
#         output_json_path=output_json_path,
#         line_numbers=line_numbers,
#     )
#     # 3. Create protoc command (back up solution) to load the FileDescriptorSet.
#     # It takes options, returns file_descriptor_set.
#     if options.use_descriptor_set():
#         file_set_original = Loader(
#             proto_definition_dirs=None,
#             proto_files=None,
#             descriptor_set=options.original_descriptor_set_file_path,
#         ).get_descriptor_set()
#         file_set_update = Loader(
#             proto_definition_dirs=None,
#             proto_files=None,
#             descriptor_set=options.update_descriptor_set_file_path,
#         ).get_descriptor_set()
#     elif options.use_proto_dirs():
#         file_set_original = Loader(
#             proto_definition_dirs=options.original_api_definition_dirs,
#             proto_files=options.original_proto_files,
#             descriptor_set=None,
#         ).get_descriptor_set()
#         file_set_update = Loader(
#             proto_definition_dirs=options.update_api_definition_dirs,
#             proto_files=options.update_proto_files,
#             descriptor_set=None,
#         ).get_descriptor_set()
#     # 4. Create the detector with two FileDescriptorSet and options.
#     # It creates output_json file and prints human-readable message if the option is enabled.
#     result = Detector(
#         file_set_original, file_set_update, options
#     ).detect_breaking_changes()
#     return len(result)


# Path: test/cli/test_detect.py
import unittest
import os
import tempfile
import json
from click.testing import CliRunner
from src.cli.detect import detect
from unittest.mock import patch
from io import StringIO

                + "google/cloud/oslogin/v1/oslogin.proto L202: An existing resource_reference option of the field `name` is removed in message `.google.cloud.oslogin.v1.UpdateSshPublicKeyRequest`.\n",
            )

    def test_oslogin_proto_beta(self):
        with patch("sys.stdout", new=StringIO()):
            runner = CliRunner()
            result = runner.invoke(
                detect,
                [
                    f"--original_api_definition_dirs=googleapis/,{self.COMMON_PROTOS_DIR}",
                    f"--update_api_definition_dirs=googleapis/,{self.COMMON_PROTOS_DIR}",
                    "--original_proto_files=googleapis/google/cloud/oslogin/v1/oslogin.proto",
                    "--update_proto_files=googleapis/google/cloud/oslogin/v1beta/oslogin.proto",
                    "--human_readable_message",
                ],
            )
            self.assertEqual(result.exit_code, 0)
            self.assertEqual(
                result.output,
                "google/cloud/oslogin/v1beta/oslogin.proto L179: Changed field behavior for an existing field `ssh_public_key` in message `.google.cloud.oslogin.v1.ImportSshPublicKeyRequest`.\n",
            )

    def test_pubsub_proto(self):
        pubsub_v1beta2 = os.path.join(
            self.GOOGLEAPI_DIR, "google/pubsub/v1beta2/pubsub.proto"
        )
        pubsub_v1 = os.path.join(self.GOOGLEAPI_DIR, "google/pubsub/v1/pubsub.proto")
        with patch("sys.stdout", new=StringIO()):
            runner = CliRunner()
            result = runner.invoke(

                detect,