From 8098216a833544dd69b0e9c4116110fdcc4d79fe Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sat, 1 Aug 2026 22:39:55 +0800 Subject: [PATCH] feat: finish packer cli (may changed in future --- packer/src/sarasacw_omrf_packer/cli.py | 74 +++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/packer/src/sarasacw_omrf_packer/cli.py b/packer/src/sarasacw_omrf_packer/cli.py index f380261..c7ada17 100644 --- a/packer/src/sarasacw_omrf_packer/cli.py +++ b/packer/src/sarasacw_omrf_packer/cli.py @@ -1,19 +1,77 @@ import argparse from dataclasses import dataclass +from pathlib import Path -@dataclass +@dataclass(frozen=True) class Cli: - manifest_path: str - output_dir: str + """Captured command-line options for the packer. + + Instances are immutable and are produced only by :func:`parse`; every + downstream stage of the pipeline reads its configuration from this object + rather than re-interpreting the command line. + """ + + manifest: Path + """Path to the ``Cargo.toml`` manifest of the project being packed.""" + + dist_dir: Path | None + """Destination directory for the distributable layout, or ``None`` when + no on-disk distribution tree is requested.""" + + dist_zip: Path | None + """Destination of the zip archive bundling the distribution tree, or + ``None`` when no archive is requested.""" def parse() -> Cli: + """Parse command-line arguments into a :class:`Cli` instance. + + Builds an :class:`argparse.ArgumentParser`, interprets ``sys.argv`` and + returns the captured options as an immutable :class:`Cli`. The process is + terminated by argparse itself on error or when ``-h/--help`` is given. + """ parser = argparse.ArgumentParser( - prog="sarasacw-omrf-packer", - description="Create distribution and generate CMake and pkg-config files.", + prog="SarasaCW OMRF Packer", + description=( + "Packaging tool of Sarasas Chip Workshop Oh My Rust FFI (OMRF). " + "Creates a CMake-style distributable layout and generates CMake " + "and pkg-config files for Rust FFI build artifacts." + ), + ) + parser.add_argument( + "-m", + "--manifest", + dest="manifest", + action="store", + type=Path, + required=True, + help="Path to the Cargo.toml manifest of the project to pack", + metavar="CARGO.TOML", + ) + parser.add_argument( + "-d", + "--dist-dir", + dest="dist_dir", + action="store", + type=Path, + required=False, + help="Directory where distributable files are installed (creates a CMake layout: bin/, include/, lib/ ...)", + metavar="DIR", + ) + parser.add_argument( + "-z", + "--dist-zip", + dest="dist_zip", + action="store", + type=Path, + required=False, + help="Path of the zip archive created from the dist-dir contents", + metavar="ZIP", ) - parser.add_argument("--manifest-path", default="Cargo.toml") - parser.add_argument("--output-dir", default="dist") args = parser.parse_args() - return Cli(manifest_path=args.manifest_path, output_dir=args.output_dir) + return Cli( + manifest=args.manifest, + dist_dir=args.dist_dir, + dist_zip=args.dist_zip, + )