feat: finish packer cli (may changed in future
This commit is contained in:
@@ -1,19 +1,77 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass(frozen=True)
|
||||||
class Cli:
|
class Cli:
|
||||||
manifest_path: str
|
"""Captured command-line options for the packer.
|
||||||
output_dir: str
|
|
||||||
|
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:
|
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(
|
parser = argparse.ArgumentParser(
|
||||||
prog="sarasacw-omrf-packer",
|
prog="SarasaCW OMRF Packer",
|
||||||
description="Create distribution and generate CMake and pkg-config files.",
|
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()
|
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,
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user