Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/scribe_data/cli/contracts/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Functions to export data contracts to the current working directory.
"""

import shutil
from pathlib import Path

from rich import print as rprint

from scribe_data.cli.contracts.filter import scribe_data_contracts


def export_contracts(destination: Path):
"""
Export the internal data contracts to the specified destination.

Parameters
----------
destination : Path
The directory path where the 'contracts' folder should be exported.

Returns
-------
None
This function does not return a value; it performs a file system operation.

Raises
------
FileExistsError
Raised if a 'contracts' directory already exists at the destination.
Exception
Raised for unexpected I/O errors during the directory copy process.
"""
source_path = scribe_data_contracts
dest_path = destination / "contracts"
try:
shutil.copytree(source_path, dest_path)
rprint("[bold green]Successfully exported data contracts.[/bold green]")
except FileExistsError as e:
rprint(f"[bold red]Error exporting data contracts: {e}[/bold red]")

except Exception as e:
rprint(f"[bold red]An error occurred: {e}[/bold red]")
16 changes: 16 additions & 0 deletions src/scribe_data/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from scribe_data.cli.cli_utils import validate_language_and_data_type
from scribe_data.cli.contracts.check import check_contracts
from scribe_data.cli.contracts.export import export_contracts
from scribe_data.cli.contracts.filter import export_data_filtered_by_contracts
from scribe_data.cli.convert import convert_wrapper
from scribe_data.cli.download import wd_lexeme_dump_download_wrapper
Expand Down Expand Up @@ -330,6 +331,16 @@ def main() -> None:
)
interactive_parser._actions[0].help = "Show this help message and exit."

# MARK: Export Contracts

export_contracts_parser = subparsers.add_parser(
"export_contracts",
aliases=["ec"],
help="Export data contracts to the PWD",
description="Export the data contracts to the PWD",
)
export_contracts_parser._actions[0].help = "Show this help message and exit."

# MARK: Check Contracts

check_contracts_parser = subparsers.add_parser(
Expand Down Expand Up @@ -573,6 +584,11 @@ def main() -> None:
else:
print("Skipping action")

elif args.command in ["export_contracts", "ec"]:
export_contracts(
destination=Path.cwd(),
)

elif args.command in ["check_contracts", "cc"]:
check_contracts(output_dir=args.output_dir)

Expand Down
Loading
Loading