Skip to main content

Renderer

Trait Renderer 

Source
pub trait Renderer: Send + Sync {
    // Required methods
    fn render_help(&self, command: &Command) -> String;
    fn render_markdown(&self, command: &Command) -> String;
    fn render_subcommand_list(&self, commands: &[Command]) -> String;
    fn render_ambiguity(&self, input: &str, candidates: &[String]) -> String;

    // Provided method
    fn render_docs(&self, registry: &Registry) -> String { ... }
}
Expand description

A pluggable renderer for command help, Markdown docs, and disambiguation messages.

Implement this trait to fully customize how argot formats its output. Use crate::Cli::with_renderer to inject your implementation.

A DefaultRenderer is provided that delegates to the module-level free functions (render_help, render_markdown, etc.).

§Examples

struct UppercaseRenderer;

impl Renderer for UppercaseRenderer {
    fn render_help(&self, command: &Command) -> String {
        argot_cmd::render_help(command).to_uppercase()
    }
    fn render_markdown(&self, command: &Command) -> String {
        argot_cmd::render_markdown(command)
    }
    fn render_subcommand_list(&self, commands: &[Command]) -> String {
        argot_cmd::render_subcommand_list(commands)
    }
    fn render_ambiguity(&self, input: &str, candidates: &[String]) -> String {
        argot_cmd::render_ambiguity(input, candidates)
    }
}

Required Methods§

Source

fn render_help(&self, command: &Command) -> String

Render a plain-text help page for a command.

Source

fn render_markdown(&self, command: &Command) -> String

Render a Markdown documentation page for a command.

Source

fn render_subcommand_list(&self, commands: &[Command]) -> String

Render a compact listing of multiple commands.

Source

fn render_ambiguity(&self, input: &str, candidates: &[String]) -> String

Render a disambiguation message for an ambiguous command token.

Provided Methods§

Source

fn render_docs(&self, registry: &Registry) -> String

Render a full Markdown reference document for all commands in a registry.

Produces a # Commands heading, a table of contents with depth-based indentation, and per-command Markdown sections separated by ---.

Implementors§