rspyts_cli/lib.rs
1//! Command-line entry points for the rspyts build orchestrator.
2//!
3//! The crate is organized as a small compiler pipeline:
4//!
5//! - `config` and `cargo` resolve authoritative user and workspace inputs;
6//! - `project` builds the synthetic bridge and validates the discovered IR;
7//! - `python` and `typescript` lower that IR into host packages;
8//! - `output` owns collision checks and transactional publication;
9//! - `cli` and `commands` provide the process-facing interface.
10//!
11//! This module owns only the process and embeddable I/O boundaries.
12
13#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
14#![forbid(unsafe_op_in_unsafe_fn)]
15
16use std::ffi::OsString;
17use std::io::{self, Write};
18
19use anyhow::Result;
20use clap::Parser;
21
22mod cargo;
23mod cli;
24mod commands;
25mod config;
26mod contract;
27mod documentation;
28mod init;
29mod output;
30mod project;
31mod python;
32mod typescript;
33
34use cli::Cli;
35
36/// Parse the current process arguments and run the selected command.
37///
38/// Normal command output is written to stdout. Recoverable watch failures are
39/// written to stderr; fatal errors are returned to the binary entry point.
40///
41/// # Errors
42///
43/// Returns an error when command input is invalid or a requested operation
44/// fails.
45pub fn run() -> Result<()> {
46 let stdout = io::stdout();
47 let stderr = io::stderr();
48 commands::execute(Cli::parse().command, &mut stdout.lock(), &mut stderr.lock())
49}
50
51/// Parse explicit arguments and run a command with caller-provided output.
52///
53/// This entry point is intended for integrations that need deterministic
54/// argument and output boundaries without replacing global process state.
55/// Include the binary name as the first argument, just as with
56/// [`std::env::args_os`].
57///
58/// # Errors
59///
60/// Returns a clap parsing error for invalid arguments, or the command error
61/// when execution fails.
62pub fn run_with<I, T>(args: I, stdout: &mut dyn Write, stderr: &mut dyn Write) -> Result<()>
63where
64 I: IntoIterator<Item = T>,
65 T: Into<OsString> + Clone,
66{
67 commands::execute(Cli::try_parse_from(args)?.command, stdout, stderr)
68}