Trait clap_generate::Generator
source · [−]pub trait Generator {
fn file_name(&self, name: &str) -> String;
fn generate(&self, app: &App<'_>, buf: &mut dyn Write);
}
Expand description
Generator trait which can be used to write generators
Required methods
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)
}
}
Generates output out of clap::App
.
Panics
May panic when called outside of the context of generate
or generate_to
Examples
The following example generator displays the clap::App
as if it is printed using std::println
.
use std::{io::Write, fmt::write};
use clap::App;
use clap_complete::Generator;
pub struct ClapDebug;
impl Generator for ClapDebug {
fn generate(&self, app: &App, buf: &mut dyn Write) {
write!(buf, "{}", app).unwrap();
}
}