def run()

in client/commands/initialize.py [0:0]


def run() -> commands.ExitCode:
    try:
        global_root: Optional[Path] = find_global_root(Path("."))
        buck_root: Optional[Path] = find_parent_directory_containing_file(
            Path("."), ".buckconfig"
        )
        current_directory: Path = Path(os.getcwd())
        configuration_path = current_directory / CONFIGURATION_FILE
        if os.path.isfile(configuration_path):
            if global_root:
                error = (
                    "Local configurations must be created in subdirectories of "
                    + f"`{str(current_directory)}` as it already contains a "
                    + "`.pyre_configuration`."
                )
            else:
                error = (
                    "A pyre configuration already exists at "
                    + f"`{str(configuration_path)}`."
                )
            raise InitializationException(error)
        local_configuration_path = current_directory / LOCAL_CONFIGURATION_FILE
        if local_configuration_path.is_file():
            raise InitializationException(
                "A local pyre configuration already exists at "
                + f"`{str(local_configuration_path)}`."
            )
        if global_root:
            configuration_path = local_configuration_path
            configuration = _get_local_configuration(current_directory, buck_root)
        else:
            configuration = _get_configuration()

        with open(configuration_path, "w+") as configuration_file:
            json.dump(configuration, configuration_file, sort_keys=True, indent=2)
            configuration_file.write("\n")
        LOG.log(
            log.SUCCESS,
            "Successfully initialized pyre!\n"
            + f"  You can view the configuration at `{configuration_path}`.\n"
            + "  You can now run the type checker with `pyre`.",
        )
        return commands.ExitCode.SUCCESS
    except InitializationException as error:
        LOG.error(f"{error}")
        return commands.ExitCode.FAILURE