Trait clap_complete::generator::Generator
source · pub trait Generator {
fn file_name(&self, name: &str) -> String;
fn generate(&self, cmd: &Command<'_>, buf: &mut dyn Write);
}
Expand description
Generator trait which can be used to write generators
Required Methods§
sourcefn file_name(&self, name: &str) -> String
fn file_name(&self, name: &str) -> String
Returns the file name that is created when this generator is called during compile time.
Panics
May panic when called outside of the context of generate
or generate_to
Examples
use clap_complete::Generator;
pub struct Fish;
impl Generator for Fish {
fn file_name(&self, name: &str) -> String {
format!("{}.fish", name)
}
}
sourcefn generate(&self, cmd: &Command<'_>, buf: &mut dyn Write)
fn generate(&self, cmd: &Command<'_>, buf: &mut dyn Write)
Generates output out of clap::Command
.
Panics
May panic when called outside of the context of generate
or generate_to
Examples
The following example generator displays the clap::Command
as if it is printed using std::println
.
use std::{io::Write, fmt::write};
use clap::Command;
use clap_complete::Generator;
pub struct ClapDebug;
impl Generator for ClapDebug {
fn generate(&self, cmd: &Command, buf: &mut dyn Write) {
write!(buf, "{}", cmd).unwrap();
}
}