python_proto_importer/lib.rs
1//! # python-proto-importer
2//!
3//! A Rust-powered CLI that brings production-grade reliability to Python gRPC/Protobuf code generation.
4//! Generate, validate, and maintain protobuf-based Python code with confidence.
5//!
6//! ## Core Features
7//!
8//! - **Automatic Import Rewriting**: Converts absolute imports to relative imports for better portability
9//! - **Built-in Quality Assurance**: Validates generated code before it reaches your project
10//! - **Comprehensive Verification**: Import testing and optional type checking with optimal settings
11//! - **Production-Ready Workflow**: Single command for generation, postprocessing, and validation
12//!
13//! ## Quick Start
14//!
15//! ```toml
16//! # pyproject.toml
17//! [tool.python_proto_importer]
18//! inputs = ["proto/**/*.proto"]
19//! out = "generated"
20//! ```
21//!
22//! Then run: `proto-importer build`
23
24#![cfg_attr(feature = "python", allow(clippy::useless_conversion))]
25
26// Module declarations
27pub(crate) mod cli;
28pub mod commands;
29pub mod config;
30pub mod doctor;
31pub(crate) mod generator {
32 pub mod protoc;
33}
34pub mod postprocess;
35pub(crate) mod python;
36pub(crate) mod utils;
37pub mod verification;
38
39// Re-export main CLI functions
40use anyhow::Result;
41
42/// Main entry point for CLI usage.
43///
44/// This function initializes the CLI application and processes command-line arguments
45/// using the standard argument parsing. It's the primary entry point when using
46/// this library as a CLI tool.
47///
48/// # Returns
49///
50/// Returns `Ok(())` on successful execution, or an `anyhow::Error` if any step
51/// in the process fails.
52///
53/// # Example
54///
55/// ```no_run
56/// use python_proto_importer::run_cli;
57///
58/// fn main() -> anyhow::Result<()> {
59/// run_cli()
60/// }
61/// ```
62pub fn run_cli() -> Result<()> {
63 cli::run_cli()
64}
65
66/// Entry point for CLI usage with custom arguments.
67///
68/// This function allows programmatic invocation of the CLI with custom arguments,
69/// useful for testing or when integrating the tool into other applications.
70///
71/// # Arguments
72///
73/// * `args` - An iterator of arguments where each item can be converted to `String`.
74/// The first argument should typically be the program name.
75///
76/// # Returns
77///
78/// Returns `Ok(())` on successful execution, or an `anyhow::Error` if any step
79/// in the process fails.
80///
81/// # Example
82///
83/// ```no_run
84/// use python_proto_importer::run_cli_with;
85///
86/// fn main() -> anyhow::Result<()> {
87/// let args = vec!["proto-importer", "build", "--no-verify"];
88/// run_cli_with(args)
89/// }
90/// ```
91pub fn run_cli_with<I, S>(args: I) -> Result<()>
92where
93 I: IntoIterator<Item = S>,
94 S: Into<String>,
95{
96 cli::run_cli_with(args)
97}