HelpFormatter

Struct HelpFormatter 

Source
pub struct HelpFormatter { /* private fields */ }
Expand description

HelpFormatter helps print usage information for the Options.

The output format is like:

usage: <cmd_syntax> [opt_usage]
[header]
    -<opt>, --<long_opt>               <description>
    -<opt>                             <description>
    --<long_opt>                       <description>
    -<opt>, --<long_opt>=[opt_name]    <description>
[footer]

Implementations§

Source§

impl HelpFormatter

Source

pub fn new(cmd_syntax: &str) -> HelpFormatter

Create a HelpFormatter with default configuration.

The cmd_syntax is typically the name of the executable with positional options. For example, "cd [<path>]".

Source

pub fn get_option_comparator( &self, ) -> Option<&dyn Fn(&AnpOption, &AnpOption) -> Ordering>

Retrieve the option comparator, which is used to sort the AnpOption when printing options.

Source

pub fn get_arg_name(&self) -> &str

Get the argument name displayed in usage.

Source

pub fn get_desc_padding(&self) -> usize

Get number of padding space for option description.

Source

pub fn get_left_padding(&self) -> usize

Get number of padding space before option.

Source

pub fn get_long_opt_prefix(&self) -> &str

Get the long option prefix.

Source

pub fn get_newline(&self) -> &str

Get the newline. For windows, it defaults to \r\n. For other operating system, it defaults to \n.

Source

pub fn get_opt_prefix(&self) -> &str

Get the option prefix.

Source

pub fn get_syntax_prefix(&self) -> &str

Get the syntax prefix.

Source

pub fn get_width(&self) -> usize

Get the max width of the output message.

Source

pub fn set_arg_name(&mut self, arg_name: &str)

Set the argument name displayed in option usage.

Source

pub fn set_desc_padding(&mut self, padding: usize)

Set number of padding space for option description.

Source

pub fn set_left_padding(&mut self, padding: usize)

Set number of padding space before option.

Source

pub fn set_newline(&mut self, newline: &str)

Set the newline characters.

Source

pub fn set_opt_comparator( &mut self, comparator: Option<Box<dyn Fn(&AnpOption, &AnpOption) -> Ordering>>, )

Set the option comparator, which is used to sort the AnpOption when printing options.

Source

pub fn set_syntax_prefix(&mut self, prefix: &str)

Set the syntax prefix, the default value is [DEFAULT_SYNTAX_PREFIX].

Source

pub fn set_width(&mut self, width: usize)

Set the maximum width of the display message, which defaults to [DEFAULT_WIDTH].

Source

pub fn set_cmd_syntax(&mut self, syntax: &str)

Set the cmd syntax, for display purpose only.

The cmd_syntax is typically the name of the executable with positional options. For example, "cd [<path>]".

Source

pub fn set_header(&mut self, header: &str)

Set header message.

Set footer message.

Source

pub fn set_auto_usage(&mut self, auto_usage: bool)

Set if auto print the option usage after cmd_syntax.

Source

pub fn print_help<T: Write>(&self, out: &mut T, options: &Options)

Print help message of the Options to the out sinks.

§Example
use std::io::{stderr};
use anpcli::{HelpFormatter, Options};
HelpFormatter::new("ls").print_help(&mut stderr(), &Options::new());
Source

pub fn print_options<T: Write>(&self, out: &mut T, options: &Options)

Print detailed information for options only.

Also see HelpFormatter, HelpFormatter::print_help.

Source

pub fn print_usage<T: Write>(&self, out: &mut T)

Print cmd syntax without option usage.

Also see HelpFormatter, HelpFormatter::print_help.

Source

pub fn print_usage_with_options<T: Write>(&self, out: &mut T, options: &Options)

Print cmd syntax with option usage.

Also see HelpFormatter, HelpFormatter::print_help.

Source

pub fn render_wrapped_text_block( &self, buffer: &mut String, next_line_tab_stop: usize, text: &str, )

Render a wrapped text block to the buffer with the max width configured. When text is wrapped, next_line_tab_stop number of space is appended.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.