Skip to main content

rspyts_cli/
lib.rs

1//! Command-line entry points for the rspyts build orchestrator.
2//!
3//! Argument syntax lives in [`cli`], while command behavior lives in
4//! [`commands`]. This module owns only the process and embeddable I/O
5//! boundaries.
6
7use std::ffi::OsString;
8use std::io::{self, Write};
9
10use anyhow::Result;
11use clap::Parser;
12
13mod cli;
14mod commands;
15mod config;
16mod contract;
17mod init;
18mod output;
19mod project;
20mod python;
21mod typescript;
22
23use cli::Cli;
24
25/// Parse the current process arguments and run the selected command.
26///
27/// Normal command output is written to stdout. Recoverable watch failures are
28/// written to stderr; fatal errors are returned to the binary entry point.
29///
30/// # Errors
31///
32/// Returns an error when command input is invalid or a requested operation
33/// fails.
34pub fn run() -> Result<()> {
35    let stdout = io::stdout();
36    let stderr = io::stderr();
37    commands::execute(Cli::parse().command, &mut stdout.lock(), &mut stderr.lock())
38}
39
40/// Parse explicit arguments and run a command with caller-provided output.
41///
42/// This entry point is intended for integrations that need deterministic
43/// argument and output boundaries without replacing global process state.
44/// Include the binary name as the first argument, just as with
45/// [`std::env::args_os`].
46///
47/// # Errors
48///
49/// Returns a clap parsing error for invalid arguments, or the command error
50/// when execution fails.
51pub fn run_with<I, T>(args: I, stdout: &mut dyn Write, stderr: &mut dyn Write) -> Result<()>
52where
53    I: IntoIterator<Item = T>,
54    T: Into<OsString> + Clone,
55{
56    commands::execute(Cli::try_parse_from(args)?.command, stdout, stderr)
57}