Skip to main content

HelpFormatter

Trait HelpFormatter 

Source
pub trait HelpFormatter {
    // Required methods
    fn format_app(&self, config: &CommandsConfig) -> String;
    fn format_command(&self, config: &CommandsConfig, command: &str) -> String;
}
Expand description

Generates help text from a runtime configuration.

Both methods receive the full CommandsConfig so implementations have access to metadata, commands, and global options.

§Object safety

This trait has no generic methods and no Self return types, so it is fully dyn-compatible. It can be used as Box<dyn HelpFormatter>.

§Example

use dynamic_cli::help::{HelpFormatter, DefaultHelpFormatter};
use dynamic_cli::config::schema::{CommandsConfig, Metadata};

let config = CommandsConfig {
    metadata: Metadata {
        version: "1.0.0".to_string(),
        prompt: "myapp".to_string(),
        prompt_suffix: " > ".to_string(),
    },
    commands: vec![],
    global_options: vec![],
};

let formatter = DefaultHelpFormatter::new();
let help = formatter.format_app(&config);
assert!(help.contains("myapp"));
assert!(help.contains("1.0.0"));

Required Methods§

Source

fn format_app(&self, config: &CommandsConfig) -> String

Generate help text for the whole application.

Lists all commands with their descriptions, and prints usage.

Source

fn format_command(&self, config: &CommandsConfig, command: &str) -> String

Generate help text for a single command.

Looks up command by name or alias and prints its arguments, options, and aliases. If the command is not found, returns an informative error string (never panics).

Implementors§