1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
mod shells;
// Std
use std::io::Write;
// Internal
use clap::App;
pub use shells::*;
/// Generator trait which can be used to write generators
pub trait Generator {
/// Returns the file name that is created when this generator is called during compile time.
///
/// # Examples
///
/// ```
/// # use std::io::Write;
/// # use clap::App;
/// use clap_generate::Generator;
///
/// pub struct Fish;
///
/// impl Generator for Fish {
/// # fn generate(&self, app: &App, buf: &mut dyn Write) {}
/// fn file_name(&self, name: &str) -> String {
/// format!("{}.fish", name)
/// }
/// }
/// ```
fn file_name(&self, name: &str) -> String;
/// Generates output out of [`clap::App`](App).
///
/// # Examples
///
/// The following example generator displays the [`clap::App`](App)
/// as if it is printed using [`std::println`].
///
/// ```
/// use std::{io::Write, fmt::write};
/// use clap::App;
/// use clap_generate::Generator;
///
/// pub struct ClapDebug;
///
/// impl Generator for ClapDebug {
/// fn generate(&self, app: &App, buf: &mut dyn Write) {
/// write!(buf, "{}", app).unwrap();
/// }
/// # fn file_name(&self, name: &str) -> String {
/// # name.into()
/// # }
/// }
/// ```
fn generate(&self, app: &App, buf: &mut dyn Write);
}