pub struct CliDocsGenerator;Expand description
CLI documentation generator for creating JSON documentation from Clap CLI structures
This is a stateless utility that uses Clap’s introspection APIs to extract comprehensive CLI metadata and convert it to a structured JSON documentation format.
§Architecture
- Uses
CommandFactorytrait to access CLI structure - Recursively traverses commands and subcommands
- Delegates JSON construction to
schema_buildermodule
§Examples
use clap::Parser;
use torrust_tracker_deployer_lib::infrastructure::cli_docs::CliDocsGenerator;
#[derive(Parser)]
struct MyCli {
#[arg(short, long)]
verbose: bool,
}
let docs = CliDocsGenerator::generate::<MyCli>()?;
assert!(docs.contains("\"name\""));Implementations§
Source§impl CliDocsGenerator
impl CliDocsGenerator
Sourcepub fn generate<T: CommandFactory>() -> Result<String, CliDocsGenerationError>
pub fn generate<T: CommandFactory>() -> Result<String, CliDocsGenerationError>
Generates JSON documentation for the given CLI type
The type must implement CommandFactory from Clap, which is automatically
provided by the #[derive(Parser)] macro.
§Type Parameters
T- The CLI type to generate documentation for (must implementCommandFactory)
§Returns
Ok(String)- The JSON documentation as a pretty-printed JSON stringErr(CliDocsGenerationError)- If documentation generation or serialization fails
§Examples
use clap::Parser;
use torrust_tracker_deployer_lib::infrastructure::cli_docs::CliDocsGenerator;
#[derive(Parser)]
#[command(name = "my-app", version = "1.0.0", about = "My application")]
struct MyCli {
#[arg(short, long)]
verbose: bool,
}
let docs = CliDocsGenerator::generate::<MyCli>()?;
assert!(docs.contains("my-app"));
assert!(docs.contains("verbose"));§Errors
Returns CliDocsGenerationError::SerializationFailed if the documentation
cannot be serialized to JSON (this should be extremely rare).
Auto Trait Implementations§
impl Freeze for CliDocsGenerator
impl RefUnwindSafe for CliDocsGenerator
impl Send for CliDocsGenerator
impl Sync for CliDocsGenerator
impl Unpin for CliDocsGenerator
impl UnsafeUnpin for CliDocsGenerator
impl UnwindSafe for CliDocsGenerator
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request