pub struct P4Cli { /* private fields */ }Expand description
A P4 CLI wrapper that extracts the embedded p4 binary to an isolated temporary directory.
Each P4Cli instance gets its own temp directory, eliminating cross-process races.
The temp directory is cleaned up on Drop.
§Example
use p4cli_20251::P4Cli;
fn main() -> std::io::Result<()> {
let p4: P4Cli = P4Cli::new()?;
let output: p4cli_20251::P4Output = p4.run(&["--help"])?;
println!("exit: {}", output.exit_code());
println!("{}", output.stdout_str()?);
Ok(())
}Implementations§
Source§impl P4Cli
impl P4Cli
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a new P4Cli instance.
The embedded p4 binary is decompressed and written to an isolated temporary directory. Each call performs a fresh decompression; there is no persistent cache (see security notes in the crate docs).
Sourcepub fn run<S: AsRef<OsStr>>(&self, args: &[S]) -> Result<P4Output>
pub fn run<S: AsRef<OsStr>>(&self, args: &[S]) -> Result<P4Output>
Convenience method: run p4 with the given arguments.
This is equivalent to self.command().args(args).run().
Sourcepub fn stream<S: AsRef<OsStr>>(&self, args: &[S]) -> Result<P4Stream>
pub fn stream<S: AsRef<OsStr>>(&self, args: &[S]) -> Result<P4Stream>
Convenience method: stream p4 output with the given arguments.
This is equivalent to self.command().args(args).stream().
Sourcepub fn command(&self) -> P4Command<'_>
pub fn command(&self) -> P4Command<'_>
Obtain a P4Command builder for fine-grained control over
working directory, environment variables, stdin, and timeout.
§Example
use p4cli_20251::P4Cli;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let p4: P4Cli = P4Cli::new()?;
let output: p4cli_20251::P4Output = p4
.command()
.arg("--help")
.timeout(Duration::from_secs(10))
.run()?;
if output.success() {
println!("{}", output.stdout_str()?);
}
Ok(())
}