pub struct CliParser { /* private fields */ }Expand description
CLI Parser - Executes binaries and parses help output
Implementations§
Source§impl CliParser
impl CliParser
Sourcepub fn with_limits(resource_limits: ResourceLimits) -> Self
pub fn with_limits(resource_limits: ResourceLimits) -> Self
Create a new CLI parser with custom resource limits
Sourcepub fn analyze(&self, binary_path: &Path) -> Result<CliAnalysis>
pub fn analyze(&self, binary_path: &Path) -> Result<CliAnalysis>
Analyze a CLI binary and extract its structure
This performs the following steps:
- Validate binary path
- Execute with –help to get help output
- Execute with –version to get version string
- Parse help output to extract options
- Detect subcommands recursively
- Build CliAnalysis structure
§Examples
use cli_testing_specialist::analyzer::CliParser;
use std::path::Path;
let parser = CliParser::new();
let analysis = parser.analyze(Path::new("/usr/bin/curl"))?;
println!("Binary: {}", analysis.binary_name);
println!("Version: {:?}", analysis.version);
println!("Options: {}", analysis.metadata.total_options);
println!("Subcommands: {}", analysis.subcommands.len());§With Custom Resource Limits
use cli_testing_specialist::analyzer::CliParser;
use cli_testing_specialist::utils::ResourceLimits;
use std::path::Path;
use std::time::Duration;
let limits = ResourceLimits::new(
1024 * 1024 * 1024, // 1GB memory
1024, // file descriptors
100, // max processes
Duration::from_secs(60), // timeout
);
let parser = CliParser::with_limits(limits);
let analysis = parser.analyze(Path::new("/usr/bin/kubectl"))?;Sourcepub fn parse_options(&self, help_output: &str) -> Vec<CliOption>
pub fn parse_options(&self, help_output: &str) -> Vec<CliOption>
Parse CLI options from help output
Sourcepub fn parse_required_args(&self, help_output: &str) -> Vec<String>
pub fn parse_required_args(&self, help_output: &str) -> Vec<String>
Parse required positional arguments from help output
Looks for Usage line and extracts <ARG> patterns:
- “Usage: cmd [OPTIONS]
<ID>” → [“ID”] - “Usage: cmd
<FILE><OUTPUT>” → [“FILE”, “OUTPUT”]
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CliParser
impl RefUnwindSafe for CliParser
impl Send for CliParser
impl Sync for CliParser
impl Unpin for CliParser
impl UnwindSafe for CliParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more